Saleh127

LO 1007

Jun 22nd, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. unsigned long long int phi[5000008];
  5. int mark[5000008];
  6. void sievephi()
  7. {
  8. for(int i=2;i<=5000002;i++)
  9. {
  10. phi[i]=i;
  11. }
  12. for(int i=2;i<=5000002;i++)
  13. {
  14. if(mark[i]==false)
  15. {
  16. for(int j=i;j<=5000002;j+=i)
  17. {
  18. mark[j]=true;
  19. phi[j]=(phi[j]/i)*(i-1);
  20. }
  21. }
  22. }
  23. for(long long int i=3;i<=5000002;i++)
  24. {
  25. phi[i]*=phi[i];
  26. phi[i]+=phi[i-1];
  27. }
  28.  
  29. }
  30.  
  31. int main()
  32. {
  33. Faster
  34. sievephi();
  35. unsigned long long int t,a,c,i,j,ans;
  36. cin>>t;
  37. for(i=1;i<=t;i++)
  38. {
  39. cin>>a>>c;
  40. ans=phi[c]-phi[a-1];
  41. printf("Case %llu: %llu\n",i,ans);
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment