Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. bool dp[5000007];
  5. ll psum[5000007];
  6. void PrimeSieve()
  7. {
  8. dp[1]=dp[0]=true;
  9. ll temp=sqrt(5000007);
  10. for(ll i=2; i<=temp; i++)
  11. {
  12. if(!dp[i])
  13. {
  14. for(ll j=i*i; j<=5000006; j+=i) dp[j]=true;
  15. }
  16. }
  17. }
  18. bool isprime(ll n)
  19. {
  20. if(n<2) return false;
  21. for(ll j=2; j<=sqrt(n); j++)
  22. {
  23. if(n%j==0) return false;
  24. }
  25. return true;
  26. }
  27. void psumm()
  28. {
  29.  
  30. for(ll i=2;i<=5000006;i++)
  31. {
  32. ll cnt=0,n=i;
  33. for(ll j=2;j<=sqrt(n);j++)
  34. {
  35. if(!dp[n])break;
  36. if(n%j==0)
  37. {
  38. while(n%j==0)
  39. n/=j;
  40. cnt+=j;
  41. }
  42. }
  43. if(n!=1)cnt+=n;
  44. if(!dp[cnt])
  45. psum[i]=1;
  46. psum[i]+=psum[i-1];
  47. // cout<<psum[i]<<endl;
  48. }
  49. }
  50. ll bigmod(ll base,ll power, ll mod)
  51. {
  52. if(power<=0) return 1;
  53. ll temp=bigmod(base,power/2,mod);
  54. if(power%2==0) return (temp*temp)%mod;
  55. else return (((temp*temp)%mod)*(base%mod))%mod;
  56. }
  57. int main()
  58. {
  59. PrimeSieve();
  60. psumm();
  61. int a,b;
  62. while(1)
  63. {
  64. int total=0;
  65. cin>>a>>b;
  66. if(a==0 && b==0 )break;
  67. total=psum[b]-psum[a-1];
  68. cout<<total<<endl;
  69. }
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement