Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define NMAX 10010
  4. using namespace std;
  5.  
  6. ifstream fin("armonica.in");
  7. ofstream fout("armonica.out");
  8.  
  9. struct fractie
  10. {
  11. long long x,y;
  12. };
  13.  
  14. fractie v[NMAX];
  15. long long nr;
  16.  
  17. int main()
  18. {
  19. long long sf = 1;
  20. long long max = 1;
  21. long long d = 2;
  22. long long p = 1;
  23. long long n;
  24.  
  25. fin>>nr;
  26.  
  27. if(nr%2==0)
  28. n = nr/2;
  29. else
  30. n = nr;
  31.  
  32. v[0].x = 1;
  33. v[0].y = 1;
  34.  
  35. while(n>1)
  36. {
  37. p = 1;
  38. while(n%d==0)
  39. {
  40. p*=d;
  41. n/=d;
  42. }
  43. sf = max;
  44. while(p>1)
  45. {
  46. v[sf].x = v[0].x * p;
  47. v[sf].y = v[0].y;
  48. sf++;
  49.  
  50. for(int i = 1;i<max;i++)
  51. {
  52. v[sf].x = v[i].x*p;
  53. v[sf].y = v[i].y;
  54. sf++;
  55. v[sf].x = v[i].x;
  56. v[sf].y = v[i].y*p;
  57. sf++;
  58. }
  59. p/=d;
  60. }
  61. d++;
  62. if(d*d>n)
  63. d = n;
  64. max = sf;
  65. }
  66. fout<<2*sf-1<<'\n';
  67. fout<<nr<<" "<<nr<<'\n';
  68. for(int i=1;i<sf;i++)
  69. {
  70. fout<<nr*(v[i].x+v[i].y)/(2*v[i].x)<<" "<<nr*(v[i].x+v[i].y)/(2*v[i].y)<<'\n';
  71. fout<<nr*(v[i].x+v[i].y)/(2*v[i].y)<<" "<<nr*(v[i].x+v[i].y)/(2*v[i].x)<<'\n';
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement