Advertisement
Saleh127

UVA 10858

Nov 7th, 2020
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll c,x,j;
  6. vector<ll>ans[10005];
  7. ll di[10005],cur[10005];
  8.  
  9. void solve(ll n,ll ind,ll i)
  10. {
  11. if(n==1)
  12. {
  13. for(j=0; j<ind; j++)
  14. {
  15. ans[x].push_back(cur[j]);
  16. }
  17. x++;
  18. return;
  19. }
  20. for( ; i<c; i++)
  21. {
  22. if(n%di[i]==0 && (((n/di[i])>=di[i] || n==di[i])))
  23. {
  24. cur[ind]=di[i];
  25.  
  26. solve(n/di[i],ind+1,i);
  27. }
  28. }
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. ios_base::sync_with_stdio(0);
  35. cin.tie(0);
  36. cout.tie(0);
  37.  
  38. ll n,i,k,l;
  39. while(cin>>n && n)
  40. {
  41. c=x=0;
  42.  
  43. for(i=2; i*i<=n; i++)
  44. {
  45. if(n%i==0)
  46. {
  47. di[c++]=i;
  48. if((i*i)!=n)
  49. {
  50. di[c++]=(n/i);
  51. }
  52. }
  53. }
  54. sort(di,di+c);
  55.  
  56. if(c)
  57. {
  58. solve(n,0,0);
  59. }
  60. cout<<x<<endl;
  61.  
  62. for(i=0; i<x; i++)
  63. {
  64. cout<<ans[i][0];
  65. for(j=1; j<ans[i].size(); j++)
  66. {
  67. cout<<" "<<ans[i][j];
  68. }
  69. cout<<endl;
  70. ans[i].clear();
  71. }
  72.  
  73. }
  74. return 0;
  75. }
  76.  
Advertisement
RAW Paste Data Copied
Advertisement