fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool isPrime(int a) {
  6. for (int i = 2; i * i <= a; ++i)
  7. if (a % i == 0)
  8. return false;
  9. return true;
  10. }
  11.  
  12. bool isDivisible(int a) {
  13. cout << a << endl;
  14. cout.flush();
  15. string res;
  16. cin >> res;
  17. return res[0] == 'y' || res[0] == 'Y';
  18. }
  19.  
  20. int main() {
  21. int c = 0;
  22. int h = 100;
  23.  
  24. for (int i = 2; i <= 10 && c < 2; ++i) {
  25. if (isPrime(i) && isDivisible(i)) {
  26. ++c;
  27. if (c >= 2) {
  28. cout << "composite" << endl;
  29. return 0;
  30. }
  31. }
  32. }
  33.  
  34. if (c < 2) {
  35. int p[] = {11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
  36. for (int pr : p) {
  37. if (isDivisible(pr)) {
  38. ++c;
  39. if (c >= 2) {
  40. cout << "composite" << endl;
  41. return 0;
  42. }
  43. }
  44. }
  45. }
  46.  
  47. cout << (c >= 2 ? "composite" : "prime") << endl;
  48. return 0;
  49. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
prime