P1008 trifecta clever loop output

https://www.luogu.com.cn/problem/P1008

Here Insert Picture Description

A need to determine the beginning of the floating range, because a, b, c are present in any case 1: 2: 3 ratio, of course, the minimum value of 123, but I have determined that the maximum value depends on the initial 321, but in fact is 327, thus for convenience will be provided to 333.
each three-digit number if the sum is equal to 1 + 2 +. . . +9, multiplication is equal to 1 * 2. . . 9 *, so that numbers can be uniquely determined do not leak.

#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    for(a = 123;a <= 333;a++)
    {
        b = a*2;
        c = a*3;
        if((a/100+a/10%10+a%10+b/100+b/10%10+b%10+c/100+c/10%10+c%10==45)&&((a/100)*(a/10%10)*(a%10)*(b/100)*(b/10%10)*(b%10)*(c/100)*(c/10%10)*(c%10)==2*3*4*5*6*7*8*9))
            cout << a << " " << b << " " << c << endl;
    }
}
Published 395 original articles · won praise 52 · views 50000 +

Guess you like

Origin blog.csdn.net/dghcs18/article/details/104324324