Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define x 10000000
- bool mark[x+5]= {false};
- long long int isprime[x],i,k,j;
- void sieve()
- {
- mark[0]=true;
- mark[1]=true;
- for(i=2; i*i<=x; i++)
- {
- if(mark[i]==false)
- {
- for(j=i*i; j<=x; j+=i)
- mark[j]=true;
- }
- }
- k=0;
- for(i=2; i<=x; i++)
- {
- if(mark[i]==false)
- isprime[k++]=i;
- }
- }
- int main()
- {
- sieve();
- long long int n;
- while(cin>>n && n)
- {
- bool flag=true;
- cout<<n<<" = ";
- if(n<0)
- cout<<"-1";
- if(n<0)
- {
- n*=-1;
- flag=false;
- }
- for(i=0; isprime[i]*isprime[i]<=n; i++)
- {
- if(n%isprime[i]==0)
- {
- while(n%isprime[i]==0)
- {
- if(flag)
- {
- cout<<isprime[i];
- flag=false;
- }
- else
- cout<<" x "<<isprime[i];
- n/=isprime[i];
- }
- }
- }
- if(n>1)
- {
- if(flag)
- cout<<n;
- else
- cout<<" x "<<n;
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement