传送门:http://codeforces.com/contest/680/problem/C
题意:底数是[2,100]中的数,现在你最多询问20次,询问为这个数是不是底数的因数,最后判断这个数是不是素数
思路:
[2,100]的素数有25个,不能都询问一遍,可以询问[2,50]里面的素数,如果全都是no就是大于50的素数,如果yes的个数大于1,那么一定不是素数,如果是一个yes,那么这个数可能是小于50的素数,也可能像4,8,9,64这种数,那么再判断一下i*i(i^2<50)就好了
代码:
#include <bits/stdc++.h>
using namespace std;
int a[19] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,4,9,25,49};
int main(){
string s;
int ans=0;
for(int i=0; i<19; i++){
printf("%d\n", a[i]);
fflush(stdout);
cin>>s;
if(s[0] == 'y')ans++;
}
if(ans>=2)puts("composite");
else puts("prime");
return 0;
}
描述: