solution.cpp 1.0 KB
Newer Older
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
#include <cstdio>
#include <iostream>
using namespace std;
int d, a1[4];
int d1(int *a1)
{
    int sum = a1[0];
    for (int i = 1; i < 4; i++)
    {
        if (sum % a1[i] != 0)
            return i;
    }
    return 0;
}
int getS(int *a1)
{
    int sum = 0, ss = 1;
    while (d1(a1) != 0)
    {
        int index = d1(a1);
        a1[0] = a1[0] * a1[index];
        ss = a1[index];
    }
    for (int i = 1; i < 4; i++)
    {
        sum += (a1[0] / a1[i]);
    }
    return sum + ss;
}
int main()
{
    for (int sum = 20; sum >= 1; sum--)
    {
        for (int a = 1; a <= 20; a++)
        {
            for (int b = 1; b <= 20; b++)
            {
                for (int c = 1; c <= 20; c++)
                {
                    a1[0] = sum, a1[1] = a, a1[2] = b, a1[3] = c;
                    if (getS(a1) == a1[0] && a > b && b > c && sum > a)
                    {
                        printf("%d, %d, %d, %d, 0\n", sum, a, b, c);
                    }
                }
            }
        }
    }
    return 0;
}