solution.cpp 1.4 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#include <cstdio>
#include <cstring>
struct bign
{
    int d[1000];
    int len;
    bign()
    {
        memset(d, 0, sizeof(d));
        len = 0;
    }
} a, b;
bign add(bign &a, bign &b)
{
    bign c;
    int carry = 0;
    for (int i = 0; i < a.len || i < b.len; i++)
    {
        int temp = a.d[i] + b.d[i] + carry;
        c.d[c.len++] = temp % 10;
        carry = temp / 10;
    }
    if (carry)
    {
        c.d[c.len++] = carry;
    }
    return c;
}
bign multi(bign &a, int &b)
{
    bign c;
    int carry = 0;
    for (int i = 0; i < a.len; i++)
    {
        int temp = a.d[i] * b + carry;
        c.d[c.len++] = temp % 10;
        carry = temp / 10;
    }
    while (carry)
    {
        c.d[c.len++] = carry % 10;
        carry /= 10;
    }
    return c;
}
void print(bign &a)
{
    for (int i = a.len - 1; i >= 0; i--)
    {
        printf("%d", a.d[i]);
    }
    printf("\n");
}
bool vis[10] = {false};

bool judge(bign &c)
{
    for (int i = 0; i <= c.len - 1; i++)
    {
        if (!vis[c.d[i]])
            return false;
    }
    return true;
}
int main()
{
    vis[0] = vis[1] = vis[4] = vis[9] = true;
    b.d[0] = 1, b.len = 1;
    a.d[0] = 0, a.len = 1;
    int num = 0;
    for (int i = 0; num < 2020; i++)
    {
        bign c = multi(a, i);
        if (judge(c))
        {
            num++;
            printf("%d:", num);
            print(c);
        }
        a = add(a, b);
    }

    return 0;
}