新手。。没看懂错哪了(40分

P1618 三连击(升级版)

yjryjr @ 2021-10-15 16:00:43


#include<stdio.h>
int gcd(int a,int b)
{
    int i;
    for(i=2;i<=3;i++)
    {
        if(a%i==0&&b%i==0)
        {
            return i;
        }
    }
}
int repeat(int a)
{
    int ret=1;
    int x=a/100,y=a/10%10,z=a%10;
    if(x!=y&&x!=z&&y!=z) ret=0;
    return ret;
}
int sum(int a)
{
    int ret=0;
    int x=a/100,y=a/10%10,z=a%10;
    return x+y+z;
}
int xx(int a)
{
    int ret=0;
    int x=a/100,y=a/10%10,z=a%10;
    return x*y*z;
}
int main()
{
    int a,b,c,ok=0;
    scanf("%d %d %d",&a,&b,&c);
    int d=gcd(gcd(a,b),c);
    a/=d; b/=d; c/=d;
    int i,j,k; 
    for(i=123;k<=987;i++)
    {
        j=(i/a)*b,k=(i/a)*c;
        if(repeat(i)==0&&repeat(j)==0&&repeat(k)==0&&sum(i)+sum(j)+sum(k)==45&&xx(i)*xx(j)*xx(k)==362880)
        {
            ok=1;
            printf("%d %d %d\n",i,j,k);
        }
    }
    if(ok==0) printf("No!!!");
    return 0;
 } 

by little_cindy @ 2021-10-15 16:19:25

@yjryjr 当三个数互质时,你的gcd函数不就没有返回了吗?


by yjryjr @ 2021-10-15 16:44:09

@little_cindy 改了下后面加了else return 1; 一样40分,,而且似乎加和不加测试的几组数据一样


|