Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ff3495e

Browse files
Create 25.1 Prime Factors.java
1 parent f8db004 commit ff3495e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎25.1 Prime Factors.java‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Richa and her daughter Ahaana are playing a game. Richa is going to tell one number and Ahaana need to tell the prime factors of the number. Help Ahaana by completing the code to find prime factor of the number. Write a method which calculate prime factors and print and call the method in main.
3+
4+
Input Format
5+
6+
An integer value
7+
8+
Constraints
9+
10+
N will be lie between 10-50
11+
12+
Output Format
13+
14+
All the prime factors will be printed exectly once with space.
15+
*/
16+
import java.io.*;
17+
import java.util.*;
18+
19+
public class Solution {
20+
21+
static void primeFactor(int x)
22+
{
23+
if(x<=1)
24+
return;
25+
26+
for(int i=2;i*i<=x;i++)
27+
{
28+
if(x%i==0)
29+
{
30+
System.out.print(i+" ");
31+
while(x%i==0)
32+
x /= i;
33+
}
34+
}
35+
if(x>1)
36+
System.out.print(x);
37+
}
38+
public static void main(String[] args) {
39+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
40+
Scanner sc = new Scanner(System.in);
41+
int n = sc.nextInt();
42+
if(n>=10 && n<=50)
43+
primeFactor(n);
44+
else
45+
System.out.print("Invalid Input");
46+
}
47+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /