Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int prime_factor(int n)
- {
- cout<<n<<" = ";
- int ans=0;
- if(n<0)
- {
- n=-n;
- cout<<-1<<" x ";
- }
- for(int i=2;i*i<=n;i++)
- {
- if(n%i==0)
- {
- while(n%i==0)
- {
- n/=i;
- cout<<i<<" x ";
- }
- }
- }
- if(n>1) cout<<n;
- }
- int main()
- {
- int n;
- while(cin>>n)
- {
- if(n==0) break;
- prime_factor(n);
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement