Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- bool dp[5000007];
- ll psum[5000007];
- void PrimeSieve()
- {
- dp[1]=dp[0]=true;
- ll temp=sqrt(5000007);
- for(ll i=2; i<=temp; i++)
- {
- if(!dp[i])
- {
- for(ll j=i*i; j<=5000006; j+=i) dp[j]=true;
- }
- }
- }
- bool isprime(ll n)
- {
- if(n<2) return false;
- for(ll j=2; j<=sqrt(n); j++)
- {
- if(n%j==0) return false;
- }
- return true;
- }
- void psumm()
- {
- for(ll i=2;i<=5000006;i++)
- {
- ll cnt=0,n=i;
- for(ll j=2;j<=sqrt(n);j++)
- {
- if(!dp[n])break;
- if(n%j==0)
- {
- while(n%j==0)
- n/=j;
- cnt+=j;
- }
- }
- if(n!=1)cnt+=n;
- if(!dp[cnt])
- psum[i]=1;
- psum[i]+=psum[i-1];
- // cout<<psum[i]<<endl;
- }
- }
- ll bigmod(ll base,ll power, ll mod)
- {
- if(power<=0) return 1;
- ll temp=bigmod(base,power/2,mod);
- if(power%2==0) return (temp*temp)%mod;
- else return (((temp*temp)%mod)*(base%mod))%mod;
- }
- int main()
- {
- PrimeSieve();
- psumm();
- int a,b;
- while(1)
- {
- int total=0;
- cin>>a>>b;
- if(a==0 && b==0 )break;
- total=psum[b]-psum[a-1];
- cout<<total<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement