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; }?
轉載于:https://www.cnblogs.com/widsom/p/7308773.html
總結
以上是生活随笔為你收集整理的Codeforces A - Bear and Prime 100(交互题)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Firefox将以HTTP明文发送密码的
- 下一篇: javaScript原型及继承