Advertisement
Saleh127

UVA 516

Aug 18th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define maX 40008
  4. #define ll long long
  5. bool marked[maX];
  6. vector<ll>p;
  7. void sieve()
  8. {
  9. marked[0]=1;
  10. marked[1]=1;
  11. for(ll i=4; i<=maX; i+=2)
  12. {
  13. marked[i]=1;
  14. }
  15. p.push_back(2);
  16. for(ll i=3; i<=maX; i+=2)
  17. {
  18. if(marked[i]==0)
  19. {
  20. p.push_back(i);
  21. for(ll j=i*i; j<=maX; j+=i+i)
  22. {
  23. marked[j]=1;
  24. }
  25. }
  26. }
  27. }
  28. int main()
  29. {
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0);
  32. cout.tie(0);
  33.  
  34. sieve();
  35.  
  36. string x;
  37.  
  38. while(getline(cin,x))
  39. {
  40. if(x=="0" && x.size()==1) break;
  41.  
  42. ll d=0,e=0,f,i,j=0,k,l,ans=1;
  43. ll ss=x.size();
  44. for(i=0; i<ss; i++)
  45. {
  46. if(x[i]==' ')
  47. {
  48. j++;
  49. if(j%2==0 && j>0)
  50. {
  51. l=pow(d,e);
  52. ans*=l;
  53. d=0;
  54. e=0;
  55. j=0;
  56. }
  57. }
  58. else if(j%2==0 || j==0)
  59. {
  60. d=d*10+(x[i]-'0');
  61.  
  62. }
  63. else if(j%2==1)
  64. {
  65. e=e*10+(x[i]-'0');
  66. }
  67. }
  68. ans*=pow(d,e);
  69. ans=ans-1;
  70. vector<ll>a,c;
  71. ll cnt;
  72. j=0;
  73. for(i=0;p[i]*p[i]<=ans;i++)
  74. {
  75. if(ans%p[i]==0)
  76. {
  77. cnt=0;
  78. while(ans%p[i]==0)
  79. {
  80. ans/=p[i];
  81. cnt++;
  82. }
  83. a.push_back(p[i]);
  84. c.push_back(cnt);
  85. }
  86. }
  87. if(ans>1)
  88. {
  89. a.push_back(ans);
  90. c.push_back(1);
  91. }
  92. for(k=a.size()-1;k>=0;k--)
  93. {
  94. if(k==a.size()-1)
  95. {
  96. cout<<a[k]<<" "<<c[k];
  97. }
  98. else cout<<" "<<a[k]<<" "<<c[k];
  99. }
  100. cout<<endl;
  101. }
  102. return 0;
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement