Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1.  
  2. #include<bits/stdc++.h>
  3. #define fastIO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  4. using namespace std;
  5.  
  6. int phi[1100000];
  7. int cntArr[1000001];
  8.  
  9. void phiSieve(int n)
  10. {
  11.  
  12. int i,j,k,temp,tempB;
  13. int cnt =0;
  14. for(i=1; i<=n; i++)
  15. {
  16. phi[i]=i;
  17. }
  18. for(i=2; i<=n; i++)
  19. {
  20. if(phi[i]==i)
  21. {
  22. phi[i]=i-1;
  23. for(j=i*2; j<=n; j+=i)
  24. {
  25. phi[j] = phi[j]/i*(i-1);
  26. }
  27. }
  28. }
  29.  
  30. for(i=2; i<=n; i++)
  31.  
  32. cntArr[i] += cntArr[phi[i]]+1;
  33. }
  34.  
  35.  
  36. }
  37. int main()
  38. {
  39. int n,i,t,a,b,k;
  40. phiSieve(1000000);
  41.  
  42.  
  43. int cnt2 =0;
  44. fastIO;
  45. scanf("%d",&t);
  46. while(t--)
  47. {
  48. scanf("%d %d %d",&a,&b,&k);
  49. cnt2=0;
  50. for(i=a; i<=b; i++)
  51. {
  52. if(cntArr[i]==k)
  53. {
  54. cnt2++;
  55. }
  56. }
  57. printf("%d\n",cnt2);
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement