fork(1) download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <vector>
  4. using namespace std;
  5. #define MAX 130000000
  6.  
  7. bool Sieve[MAX+1];
  8. vector<long long> Factors;
  9.  
  10. long long N,t,b;
  11. int ans=0;
  12.  
  13. void Fact()
  14. {
  15. long long i;
  16.  
  17. Factors.clear();
  18.  
  19. for (i=1;i*i<=b;i++)
  20. {
  21. if (!Sieve[i])
  22. {
  23. while (b%i==0)
  24. {
  25. Factors.push_back((long long)i);
  26. b/=i;
  27. }
  28. }
  29. }
  30.  
  31. if (b>1)
  32. {
  33. Factors.push_back(b);
  34. }
  35.  
  36. return;
  37. }
  38.  
  39. void Generate(int f,long long number,bool skipped_last)
  40. {
  41. if (f==Factors.size())
  42. {
  43. if (number<=t)
  44. {
  45. ans++;
  46. }
  47.  
  48. return;
  49. }
  50.  
  51. if (number>t)
  52. return;
  53.  
  54. Generate(f+1,number,true);
  55.  
  56. if (f>0)
  57. {
  58. if (Factors[f]==Factors[f-1] && skipped_last)
  59. return;
  60. }
  61.  
  62. Generate(f+1,number*Factors[f],false);
  63.  
  64. return;
  65. }
  66.  
  67. int main()
  68. {
  69. int i,j;
  70. int test=0;
  71.  
  72. Sieve[1]=true;
  73. for (i=2;i*i<=MAX;i++)
  74. {
  75. if (!Sieve[i])
  76. {
  77. for (j=i*i;j<=MAX;j+=i)
  78. {
  79. Sieve[j]=true;
  80. }
  81. }
  82. }
  83.  
  84. while(!cin.eof())
  85. {
  86. cin>>N;
  87.  
  88. if (cin.eof())
  89. break;
  90.  
  91. cin>>t;
  92. cin>>b;
  93.  
  94. t%=N;
  95.  
  96. test++;
  97.  
  98. ans=0;
  99. Fact();
  100. Generate(0,1,false);
  101.  
  102. if (ans%2==0)
  103. printf("Case %d: Off\n",test);
  104. else
  105. printf("Case %d: On\n",test);
  106. }
  107.  
  108. return 0;
  109. }
  110.  
Success #stdin #stdout 3.38s 130112KB
stdin
Standard input is empty
stdout
Standard output is empty