1 solutions

  • 0
    @ 2023-12-19 10:52:13
    #include <iostream>
    #include <math.h>
    #include <bits/stdc++.h>
    using namespace std;
    int prime (int x){
        int flag = 1;
    	if(x == 2) flag = 1;
    	for(int i = 3 ;i < sqrt(x);i++){
    		if(x % i == 0){
    			flag = 0;
    			break;
    		}
    	}
    	return (flag);
    }
    int main()
    {
    	int n;
    	cin >> n;
    	int i = 2;
    	int j = 0;
    	int flag = 1;
    	int a[1005];
    	a[0] = 0;
    	do{
    		if(n%i == 0 && prime(i) == 1){
    			for(int k = 0 ;k <= j ;k++){
    				if(a[k] == i){
    					flag = 0;
    				}
    			}
    			if(flag == 1){
    				j++;
    				a[j] = i;
    			}
    			n /= i;
    			i = 2;
    		} else{
    			i++;
    		}
    		flag = 1;
    	}while(n != 1);
    	for(int i = 1 ;i <= j ;i++){
    		cout << a[i] << " ";
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    1688
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    10
    Tags
    # Submissions
    6
    Accepted
    2
    Uploaded By