码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-08-08 20:44:10      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:int   strong   string   span   out   problem   end   href   bit   

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(交互题)

标签:int   strong   string   span   out   problem   end   href   bit   

原文地址:http://www.cnblogs.com/widsom/p/7308773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!