Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pronic Number #Hacktober Fest #2390

Closed
SuhaniSaha opened this issue Oct 1, 2021 · 3 comments
Closed

Pronic Number #Hacktober Fest #2390

SuhaniSaha opened this issue Oct 1, 2021 · 3 comments
Labels

Comments

@SuhaniSaha
Copy link

Respected Sir,
Can I work on the algorithm/code for checking if a number is a pronic number or not.I did not find it in the Java/Maths folder.It can be added there.A pronic number is a number which is the product of two consecutive integers .i.e. a number of the form n(n + 1).
Thank you.
#Hacktoberfest

@ritweekraj2802
Copy link
Contributor

Dear sir/maam , below is the algorithm , code and output of pronic number.
If you like it please assign this to me .

A pronic number is such a number which can be represented as a product of two consecutive positive integers. By multiplying these two consecutive positive integers, there can be formed a rectangle which is represented by the product or pronic number. So it is also known as Rectangular Number.
The first few Pronic numbers are:
0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 . . . . . .
Pronic number is a number which is the product of two consecutive integers, that is, a number n is a product of x and (x+1). The task is to check if a given number is pronic or not.

Mathematical Representation:

If x is a pronic number, then x=n(n+1) ∀ n∈N0
Where, N0={0, 1, 2, 3, 4, ....}, (A set of Natural Numbers)
Examples:

Input : 56
Output : YES
Explanation: 56 = 7 * 8 i.e 56 is a product
of two consecutive integers 7 and 8.

Input : 65
Output : NO
Explanation: 65 cannot be represented as a
product of any two consecutive integers.

Algorithm:
Step 1: Evaluate the square root value of the given number.
Step 2: Calculate the floor value of that square root.
Step 3: Calculate the product of value calculated in step-2
and its next consecutive number.
Step 4: Check the product value in step-3 with the given number.
Step 4.1: If the condition satisfies,
then the number is a pronic number.
Step 4.2: Otherwise the number is not a pronic number.

code:

// Java program to check if a number is pronic or not

import java.io.;
import java.util.
;
import java.math.*;

class Pronic
{

// Function to check Pronic Number
static boolean pronic_check(int n)
{
	int x = (int)(Math.sqrt(n));

	// Checking Pronic Number by
	// multiplying consecutive numbers
	if (x * (x + 1) == n)
		return true;
	else
		return false;
}

// Driver Code
public static void main(String[] args)
{
	Scanner sr=new Scanner(system.in)
	int t=sr.nextInt();
	while(t-->0){
	int n=sr.nextInt();
	if (pronic_check(n)==true)
		System.out.println("YES");
	else
		System.out.println("NO");}
}

}

@github-actions
Copy link

github-actions bot commented Nov 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 2, 2021
@github-actions
Copy link

github-actions bot commented Dec 6, 2021

Please reopen this issue once you add more information and updates here. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions!

@github-actions github-actions bot closed this as completed Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants