fork download
  1. #include <stdio.h>
  2. #include <assert.h>
  3.  
  4. const int dmax=1000001;
  5. int a[dmax];
  6.  
  7. int ab[5]= {0,1,2,2,1};
  8.  
  9. int log(int n)
  10. {
  11. int ans=0;
  12. while (n >= 4)
  13. {
  14. n/=4;
  15. ans++;
  16. }
  17. return ans;
  18. }
  19.  
  20. int pow(int n)
  21. {
  22. int i,ans;
  23. ans=1;
  24. for (i=1; i<=n; i++)
  25. ans*=4;
  26. return ans;
  27. }
  28.  
  29. int ans(int n)
  30. {
  31. int l,p,r,c,aux;
  32. bool conj;
  33.  
  34. if (n == 1)
  35. return 1;
  36. if (n == 2)
  37. return 2;
  38. if (n == 3)
  39. return 2;
  40. if (n == 4)
  41. return 1;
  42. l=log(n);
  43. p=pow(l);
  44. if (p == n)
  45. return 1;
  46. r=n%p;
  47. c=n/p;
  48. if (r == 0)
  49. {
  50. if (c == 1 || c == 4)
  51. return 1;
  52. else
  53. return 2;
  54. }
  55. if (r > 0)
  56. c++;
  57. conj=false;
  58. if (c == 2 || c == 3)
  59. conj=true;
  60. aux=ans(r);
  61. if (conj)
  62. {
  63. if (aux == 1)
  64. aux=2;
  65. else
  66. aux=1;
  67. }
  68. return aux;
  69. }
  70.  
  71. int main()
  72. {
  73. FILE *f;
  74. int n = dmax-1,nrcif,i,j;
  75. if (n > 4)
  76. {
  77. nrcif=4;
  78. a[1]=1;
  79. a[2]=2;
  80. a[3]=2;
  81. a[4]=1;
  82. i=5;
  83. while (i <= n)
  84. {
  85. j=1;
  86. while (j <= nrcif && i <= n)
  87. {
  88. if (a[i-nrcif] == 1)
  89. a[i]=2;
  90. else
  91. a[i]=1;
  92. i++;
  93. j++;
  94. }
  95. j=1;
  96. while (j <= nrcif && i <= n)
  97. {
  98. if (a[i-2*nrcif] == 1)
  99. a[i]=2;
  100. else
  101. a[i]=1;
  102. i++;
  103. j++;
  104. }
  105. j=1;
  106. while (j <= nrcif && i <= n)
  107. {
  108. a[i]=a[i-3*nrcif];
  109. i++;
  110. j++;
  111. }
  112. nrcif=nrcif*4;
  113. }
  114. }
  115.  
  116. for (int i = 1; i < 100000; i++) {
  117. if (ans(i) != a[i]) {
  118. printf("%d\n", i);
  119. }
  120. }
  121. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:5:5: error: variably modified ‘a’ at file scope
 int a[dmax];
     ^
prog.c:9:5: warning: conflicting types for built-in function ‘log’
 int log(int n)
     ^~~
prog.c:20:5: warning: conflicting types for built-in function ‘pow’
 int pow(int n)
     ^~~
prog.c: In function ‘ans’:
prog.c:32:5: error: unknown type name ‘bool’
     bool conj;
     ^~~~
prog.c:57:10: error: ‘false’ undeclared (first use in this function)
     conj=false;
          ^~~~~
prog.c:57:10: note: each undeclared identifier is reported only once for each function it appears in
prog.c:59:14: error: ‘true’ undeclared (first use in this function)
         conj=true;
              ^~~~
prog.c: In function ‘main’:
prog.c:73:11: warning: unused variable ‘f’ [-Wunused-variable]
     FILE *f;
           ^
stdout
Standard output is empty