POJ 1426

同时也是 LETTers 2015 Summer II round 02-B - F

#include <cstdio>
#include <iostream>

using namespace std;

const int N = 1e7;

int mod[N];
int main()
{
    int i, n;

    //freopen("F.in", "r", stdin);
    while(~scanf("%d", &n) && n != 0)
    {
        mod[1]= 1 % n;
        for(i = 2; mod[i-1] != 0; i++)
        {
            mod[i] = (mod[i/2] * (10 % n) + i % 2) % n;
        }

        i--;
        int p = 0;
        while(i)
        {
            mod[p++] = i % 2;
            i /= 2;
        }

        while(p)
        {
            printf("%d", mod[--p]);
        }
        puts("");
    }
    return 0;
}
添加新评论