Advertisement
Saleh127

UVA 11327

Nov 6th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  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. #define maX 200005
  6. ll phi[maX];
  7. void seivePhi()
  8. {
  9. phi[0]=0;
  10. phi[1]=2;
  11. ll i,j;
  12. for(i=2; i<=maX; i++)
  13. {
  14. phi[i] = i;
  15. }
  16. for(i=2; i<=maX; i++)
  17. {
  18. if(phi[i]==i)
  19. {
  20. for(j=i; j<=maX; j+=i)
  21. {
  22. phi[j] = phi[j]/i * (i-1);
  23. }
  24. }
  25. phi[i]=phi[i]+phi[i-1];
  26. }
  27. }
  28. int main()
  29. {
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0);
  32. cout.tie(0);
  33.  
  34. seivePhi();
  35.  
  36. ll a,b,c,d,e,f,i,j,k,l;
  37.  
  38. while(cin>>a && a)
  39. {
  40. if(a==1)
  41. {
  42. cout<<"0/1"<<endl;
  43. }
  44. else if(a==2)
  45. {
  46. cout<<"1/1"<<endl;
  47. }
  48. else
  49. {
  50. ///b/c;
  51.  
  52. b=lower_bound(phi,phi+maX,a)-phi;
  53.  
  54. c=a-phi[b-1];
  55.  
  56. d=0;
  57.  
  58. for(i=1;i<=b;i++)
  59. {
  60. if(__gcd(i,b)==1)
  61. {
  62. d++;
  63. }
  64. if(d==c)
  65. {
  66. cout<<i<<"/"<<b<<endl;
  67. break;
  68. }
  69. }
  70.  
  71. }
  72. }
  73.  
  74.  
  75. return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement