首页 > 代码库 > Codeforces A - Bear and Prime 100(交互题)

Codeforces A - Bear and Prime 100(交互题)

A - Bear and Prime 100

思路:任何一个合数都可以写成2个以上质数的乘积。在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积。

所以打一个质数加这四个数的表:{2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49},询问19次,如果能被整出两次以上,说明是合数,否则是质数。

 

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
int a[19]={2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49};
int main()
{
    int i=0,k=0;
    string s;
    while(i<19)
    {
        cout<<a[i++]<<endl;
        cin>>s;
        if(s=="yes")k++;
    }
    if(k>=2)cout<<"composite"<<endl;
    else cout<<"prime"<<endl;
    return 0;
}

 

Codeforces A - Bear and Prime 100(交互题)