CodeForces679A

清疚 2023-06-02 11:58 150阅读 0赞

CodeForces679A
也是交互题,这个要稍微难一些.
考虑的过程大概是:
\(1\)肯定没有问的价值,如果问过\(2\),那么除了\(4\)之外的偶数都不用问了.
要问\(4\)的原因是,如果这个数字是\(4\),那就会被误判为\(prime\).
然后,质数是要问的,最后判断问出来的数字中约数是否大于等于\(2\)个,是的话就是合数,否则就是偶数.
但这样会在完全平方数的时候出错,因为它们可能会有一对质数相乘得到,然后就冇了.所以我们就再判断一下完全平方数.
需要注意的是,只询问小于等于\(50\)的完全平方数和质数就行了,完全平方数也不用全都去问,不全问的原理和问了\(2\)就不用问大于\(4\)的偶数一样.
\(Code:\)

  1. #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <string> #include <vector> #include <queue> #include <cmath> #include <ctime> #include <map> #include <set> #define MEM(x,y) memset ( x , y , sizeof ( x ) ) #define rep(i,a,b) for (int i = a ; i <= b ; ++ i) #define per(i,a,b) for (int i = a ; i >= b ; -- i) #define pii pair < int , int > #define X first #define Y second #define rint read<int> #define int long long #define pb push_back using std::set ; using std::pair ; using std::max ; using std::min ; using std::priority_queue ; using std::vector ; using std::swap ; using std::sort ; using std::unique ; using std::greater ; template < class T > inline T read () { T x = 0 , f = 1 ; char ch = getchar () ; while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) f = - 1 ; ch = getchar () ; } while ( ch >= '0' && ch <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ; ch = getchar () ; } return f * x ; } template < class T > inline void write (T x) { static T stk[100] , top = 0 ; if ( x == 0 ) { putchar ('0') ; return ; } if ( x < 0 ) { x = - x ; putchar ( '-' ) ; } while ( x ) { stk[++top] = x % 10 ; x /= 10 ; } while ( top ) { putchar ( stk[top--] + '0' ) ; } putchar ('\n') ; } int p[55] , cnt , d[] = { 0 , 4 , 9 , 25 , 49 } , tot ; char ans[5] ; inline bool check (int x) { if ( x == 1 ) return false ; for (int i = 2 ; i * i <= x ; ++ i) if ( x % i == 0 ) return false ; return true ; } signed main (int argc , char * argv[]) { rep ( i , 1 , 50 ) if ( check ( i ) ) p[++cnt] = i ; rep ( i , 1 , cnt ) { printf ("%lld\n" , p[i] ) ; fflush ( stdout ) ; scanf ("%s" , ans ) ; if ( ans[0] == 'y' ) ++ tot ; } rep ( i , 1 , 4 ) { printf ("%lld\n" , d[i] ) ; fflush ( stdout ) ; scanf ("%s" , ans ) ; if ( ans[0] == 'y' ) ++ tot ; } puts ( tot < 2 ? "prime" : "composite" ) ; system ("pause") ; return 0 ; }

转载于:https://www.cnblogs.com/Equinox-Flower/p/11470908.html

发表评论

表情:
评论列表 (有 0 条评论,150人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CodeForces679A

    [CodeForces679A][] 也是交互题,这个要稍微难一些. 考虑的过程大概是: \\(1\\)肯定没有问的价值,如果问过\\(2\\),那么除了\\(4\

    相关 CodeForces1214A

    [CodeForces1214A][] 说起来你们可能不信,这题硬生生卡了我\\(1h\\),我想了背包,扩欧,二分....等等一坨办法.结果最后还是用了\\(bfs\\)

    相关 codeforce 141A

    /字符串问题 没AC的人可能是没看清楚题目吧, 先大概说下题目大意: 给你3个字符串,如果第一个串和第二个串组合在一起可以等于第三个串就输出“Y

    相关 codeforce 185 A——Plant

    题意:给定一个大三角形,然后每次按照图片分割成4个小三角形,问n次后有多少个向上的三角形。 思路:矩阵快速幂,可以发现,每一个向上的的可以在下一次产生3个向上的,1