#include<bits/stdc++.h> using namespace std; bool str[65600]; void prime(){ str[1]=1; for(int i=2;i*i<65537;++i){ if(!str[i]){ for(int j=i*i;j<=65537;j+=i) str[j]=1; } } } int main(){ prime(); int n,m; while(cin>>n>>m&&n!=EOF){ long long int ans=0; if(n>m) swap(n,m); for(int i=n+1;i<m;++i){ if(!str[i]){ ans+=i; } } cout<<ans<<endl; } } |
Double click to view unformatted code.