Codechef April Challenge 2014, Long Contest POTATOES - "Farmer Feb" editorial: http://discuss.codechef.com/questions/41180/potatoes-editorial
Codechef April Challenge 2014, Long Contest POTATOES - "Farmer Feb" solution:
#include <iostream> #include <cstdio> using namespace std; const int n=1e6, l=1e3; int p[n]; int main() { for(int i=0; i<n; i++) p[i]=0; p[0]=p[1]=1; for(int i=2; i<l; i++) { if(p[i]==1) continue; for(int j=i*i; j<n; j+=i) p[j]=1; } int x, y, t, a; scanf("%d", &t); while(t--) { scanf("%d%d", &x, &y); a=x+y+1; while(p[a]==1) a++; printf("%d\n", a-x-y); } return 0; }
No comments:
Post a Comment