1. 程式人生 > >求不定方程的所有解

求不定方程的所有解

#include<stdio.h>
int main()
{
    int n,m,t;
    int a,b,c;
    int i,j;
    while(scanf("%d",&t)!=EOF)
    {
        while(t--)
        {
            int count=0;
            scanf("%d%d%d",&a,&b,&c);
            for(i=1;i<=c;i++)
            {
                for(j=1;j<=c;j++)
                {
                    if(a*i+b*j==c)
                    {
                        printf("%d %d\n",i,j);
                        count++;
                    }
                }
            }
            if(count==0)
            {
                printf("No\n");
            }
        }
    }
    return 0;
}

#include<stdio.h> int main() {      int a, b, c, x, t, no;      scanf ( "%d" ,&t);      while (t--)      {          scanf ( "%d%d%d"
,&a,&b,&c);          no=1;          for (c-=a,x=1;c>=b;c-=a,x++)              if (c%b==0)                 
no=0, printf ( "%d %d\n" ,x,c/b);          if (no)              puts ( "No" );      }      return 0; }