标签:
http://xcacm.hfut.edu.cn/problem.php?id=1212
模拟大发
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; bool judge_prime(int k) { int i; int u=int(sqrt(k*1.0)); for(i=2;i<=u;i++) { if(k%i==0) return 0; } return 1; } int main() { int i,j,m,n,T,a,b; scanf("%d",&T); while(T--) { scanf("%d%d%d%d",&n,&m,&a,&b); bool good=false,hello=false; while(1) { if(a>n) a=1; if(a<1) a=n; hello=judge_prime(b); if(a==m) { if(hello) { cout<<"duang"<<endl; break; } else { cout<<b<<endl; break; } } if(hello) { if(good==true) good=false; else good=true; } if(good==false) { a++; b++; } else if(good==true) { a--; b++; } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/dzzy/p/5467342.html