Wooph

pd

Mar 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. # include <iostream>
  2. # include <algorithm>
  3. using namespace std;
  4.  
  5. int D[205];
  6. short nr,da,Sol[205];
  7. unsigned long long S;
  8.  
  9. inline void divi(int x)
  10. {
  11. int i=0,d=2;
  12. while (x>1)
  13. {
  14. if (d*d==x)
  15. {
  16. D[i++]=d;
  17. x=1;
  18. }
  19. else
  20. {
  21. if (x%d==0)
  22. {
  23. D[i++]=d;
  24. D[i++]=x/d;
  25. }
  26. d++;
  27. }
  28. if (d*d>x)
  29. x=1;
  30. }
  31. nr=i;
  32. sort(D,D+nr);
  33. }
  34.  
  35. inline void back(int poz, int di, unsigned long long s)
  36. {
  37. if (s==S)
  38. {
  39. da=1;
  40. for (int i=0;i<poz;i++)
  41. cout<<D[Sol[i]]<<' ';
  42. cout<<'\n';
  43. }
  44. else
  45. {
  46. unsigned long long p;
  47. short co=1;
  48. for (int i=di; co && i<nr; i++)
  49. {
  50. p=s*D[i];
  51. if (p<=S)
  52. {
  53. Sol[poz]=i;
  54. back(poz+1, i+1, p);
  55. }
  56. else
  57. co=0;
  58. }
  59. }
  60. }
  61.  
  62. int main (void)
  63. {
  64. cin>>S;
  65. divi(S);
  66. back(0,0,1);
  67. if (!da)
  68. cout<<"NU EXISTA";
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment