Advertisement
erfanul007

UVa 516

Jul 19th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // #include <iostream>
  3. // #include <cstdio>
  4. // #include <cstdlib>
  5. // #include <algorithm>
  6. // #include <cmath>
  7. // #include <vector>
  8. // #include <set>
  9. // #include <map>
  10. // #include <queue>
  11. // #include <ctime>
  12. // #include <cassert>
  13. // #include <complex>
  14. // #include <string>
  15. // #include <cstring>
  16. // #include <queue>
  17. // #include <bitset>
  18.  
  19. using namespace std;
  20.  
  21. // #pragma GCC optimize("Ofast,no-stack-protector")
  22. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  23. // #pragma GCC optimize("unroll-loops")
  24.  
  25.  
  26. #define ll long long int
  27. #define vi vector< int >
  28. #define vll vector< ll >
  29.  
  30. #define sc scanf
  31. #define pf printf
  32. #define cspf(i) pf("Case %d: ", i)
  33. #define spc pf(" ")
  34. #define line pf("\n")
  35.  
  36. #define ff first
  37. #define ss second
  38. #define mp make_pair
  39. #define pb push_back
  40. #define ppb pop_back
  41. #define tp(v,j) get<j>(v)
  42. #define Log(b,x) (log(x)/log(b))
  43.  
  44. #define FOR(i,x,y) for(int i = int(x); i < int(y); i++)
  45. #define ROF(i,x,y) for(int i = int(x)-1; i >= int(y); i--)
  46. #define clr(arr,x) memset(arr, x, sizeof arr)
  47. #define vout(v,sz) for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
  48. #define all(v) v.begin(), v.end()
  49. #define rall(v) v.rbegin(), v.rend()
  50. #define unq(v) sort(all(v)),(v).resize(unique(all(v))-v.begin())
  51. #define fastIO ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
  52.  
  53. #define sc1(x) sc("%d",&x)
  54. #define sc2(x,y) sc("%d %d", &x, &y)
  55. #define sc3(x,y,z) sc("%d %d %d", &x, &y, &z)
  56. #define scl1(x) sc("%lld",&x);
  57. #define scl2(x,y) sc("%lld %lld", &x, &y)
  58. #define scf1(x) sc("%lf",&x)
  59. #define scf2(x,y) sc("%lf %lf", &x, &y)
  60.  
  61. #define pf1(x) pf("%d",x)
  62. #define pf2(x,y) pf("%d %d", x, y)
  63. #define pf3(x,y,z) pf("%d %d %d", x, y, z)
  64. #define pfl1(x) pf("%lld",x)
  65. #define pfl2(x,y) pf("%lld %lld",x,y)
  66.  
  67. #define MOD 10056
  68. #define MaxN 100
  69. #define MAX (int)(1e9+7)
  70. #define inf 0x3f3f3f3f
  71. #define PI acos(-1.0) // 3.1415926535897932
  72. #define eps 1e-6
  73.  
  74. template <class T> inline T bigMod(T p,T e,T M){T ret=1; for(;e>0;e>>=1){ if(e&1) ret=(ret*p)%M; p=(p*p)%M;} return (T)ret;}
  75. template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
  76. template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
  77. template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
  78. template <class T> inline T SQR(T a){return a*a;}
  79.  
  80. int dx[] = { 1,-1, 0, 0};
  81. int dy[] = { 0, 0, 1,-1};
  82.  
  83.  
  84. int main(){
  85.  
  86. #ifndef ONLINE_JUDGE
  87. clock_t tStart = clock();
  88. freopen("input.txt", "r", stdin);
  89. freopen("output.txt", "w", stdout);
  90. #endif
  91.  
  92. int n, x;
  93.  
  94. while(sc1(n)){
  95. if(n==0) break;
  96. sc1(x);
  97. vector< pair< int, int > > v,e;
  98. v.pb(mp(n,x));
  99. char c;
  100.  
  101. while(sc("%c",&c)){
  102. if(c=='\n') break;
  103. sc2(n,x);
  104. v.pb(mp(n,x));
  105. }
  106. int ans = 1;
  107. for(int i=0; i<v.size(); i++){
  108. n = v[i].ff;
  109. x = v[i].ss;
  110. while(x--){
  111. ans*=n;
  112. }
  113. }
  114. ans--;
  115.  
  116. for(int i=2; i*i<=ans; i++){
  117. if(ans%i==0){
  118. int c=0;
  119. while(ans%i==0){
  120. c++;
  121. ans/=i;
  122. }
  123. e.pb(mp(i,c));
  124. }
  125. }
  126. if(ans>1) e.pb(mp(ans, 1));
  127.  
  128. sort(rall(e));
  129.  
  130. for(int i=0; i<e.size(); i++){
  131. if(i) spc;
  132. pf("%d %d",e[i].ff, e[i].ss);
  133. }
  134. line;
  135.  
  136. }
  137.  
  138.  
  139. #ifndef ONLINE_JUDGE
  140. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  141. #endif
  142.  
  143. return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement