fork download
  1. //#define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include<bits/stdc++.h>
  4. #include<fstream>
  5. #include<cstdio>
  6. typedef long long ll;
  7. using namespace std;
  8.  
  9. void winter_is_coming()
  10. {
  11. std::ios_base::sync_with_stdio(0);
  12. cin.tie(NULL); cout.tie(NULL );
  13. }
  14. void file()
  15. {
  16. #ifndef ONLINE_JUDGE
  17. freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
  18. #endif
  19. }
  20. vector<int>v;
  21. /*vector<int>p;
  22. bool isp(int x)
  23. {
  24.   for(int i=2;i*i<=x;i++)
  25.   {
  26.   if(x%i==0)return false;
  27.   }
  28.   if(x==1) return false;
  29.   return true ;
  30. }
  31. void primes()
  32. {
  33.   for(int i=2;i*i<=1e9;i++)
  34.   {
  35.   if(isp(i))p.push_back(i);;
  36.   }
  37. }*/
  38. void getdiv(ll x)
  39. {
  40. v.clear();
  41. if(x<0) v.push_back(-1),x*=(-1);
  42.  
  43. for(ll i=2;i*i<=x;i++)
  44. {
  45. if(x==1)return;
  46. while(x%i==0)
  47. {
  48. v.push_back(i);
  49. x/=i;
  50. }
  51. }
  52. //if x != 1 that means its a prime greater than all we have but it cant be nonprime num
  53. if(x>1) v.push_back(x);
  54. return;
  55. }
  56. int main()
  57. {
  58. winter_is_coming();
  59.  
  60. ll n;
  61. //getdiv(190);
  62. while(cin>>n && n)
  63. {
  64. if(n==-1)
  65. {
  66. cout<<"-1 = -1 x \n"; continue;
  67. }
  68. getdiv(n);
  69. cout<<n<<" = ";
  70. for(int i=0;i<v.size();i++)
  71. {
  72. if(i==0) cout<<v[i];
  73. else cout<<" x "<<v[i];
  74. } cout<<"\n";
  75. }
  76.  
  77.  
  78. return 0;
  79. }
  80.  
Success #stdin #stdout 0s 15240KB
stdin
49
1073741824
1
-1
64
-190
-191
-192
-193
-194 
195 
196
197
198 
199
200
2147483647 
2147483646
-2147483647 
-2147483646
0
stdout
49 = 7 x 7
1073741824 = 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2
1 = 
-1 = -1 x 
64 = 2 x 2 x 2 x 2 x 2 x 2
-190 = -1 x 2 x 5 x 19
-191 = -1 x 191
-192 = -1 x 2 x 2 x 2 x 2 x 2 x 2 x 3
-193 = -1 x 193
-194 = -1 x 2 x 97
195 = 3 x 5 x 13
196 = 2 x 2 x 7 x 7
197 = 197
198 = 2 x 3 x 3 x 11
199 = 199
200 = 2 x 2 x 2 x 5 x 5
2147483647 = 2147483647
2147483646 = 2 x 3 x 3 x 7 x 11 x 31 x 151 x 331
-2147483647 = -1 x 2147483647
-2147483646 = -1 x 2 x 3 x 3 x 7 x 11 x 31 x 151 x 331