-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFACT0.cpp
43 lines (40 loc) · 851 Bytes
/
FACT0.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld n;
cin>>n;
while(n!=0)
{
lld val=n;
map <lld,lld> mp;
map <lld,lld> :: iterator it;
while (n % 2 == 0)
{
mp[2]++;
n = n/2;
}
for(lld i=3;i<=sqrt(n);i+=2)
{
if(n%i==0)
{
while(n%i==0)
{
mp[i]++;
n/=i;
}
}
}
if(n>1)
mp[n]++;
for(it=mp.begin();it!=mp.end();it++)
{
cout<<it->first<<"^"<<it->second<<" ";
}
cout<<endl;
cin>>n;
}
}