[ create a new paste ] login | about

Link: http://codepad.org/nInLkH37    [ raw code | output | fork ]

C, pasted on Oct 18:
#include <stdio.h>
#include <limits.h>

void sol(unsigned n) {
  unsigned m, s, t, c;
  m = n;
  c = s = 0;
  while ((t = m % 9) == 0) {
    if (t) break;
    m /= 9;
    c++;
  }
  for (;;) {
    s += (m % 9);
    m /= 9;
    if (m == 0) break;
    s *= 10;
  }
if (n == 801) printf("c=%d\n", c);
  while (c > 0) {
    s *= 10;
    --c;
  }
  if (n == s)
    printf("%d\n", n); fflush(stdout);
}

int main() {
  unsigned i;
  for (i =1; i <= UINT_MAX - 1; i++)
    sol(i);
}
/* end */


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1
2
3
4
5
6
7
8
445
c=1
313725
3454446

Timeout


Create a new paste based on this one


Comments: