Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- class GFG
- {
- public static void primeFactors(int n)
- {
- Set<Integer> set=new HashSet<Integer>();
- while (n%2==0)
- {
- set.add(2);
- n /= 2;
- }
- for (int i = 3; i <= Math.sqrt(n); i+= 2)
- {
- while (n%i == 0)
- {
- set.add(i);
- n /= i;
- }
- }
- if (n > 2)
- set.add(n);
- for(Integer i:set){
- System.out.print(i+" ");
- }
- }
- public static void main (String[] args)
- {
- Scanner sc=new Scanner(System.in);
- int n=sc.nextInt();
- primeFactors(n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment