求佩尔方程的解

#include <stdio.h>
#include <math.h>
int main()
{     
    int n;
    while(scanf("%d",&n)!=EOF){
    long j,i,k;
      
        for(k=1;k<=n;k++){
            int a;      
            scanf("%d",&a) ;
        int flag=0;
        for(i=1;i<=10000;i++){
            
              if((int)sqrt(1+a*i*i)*(int)sqrt(1+a*i*i)==1+a*i*i)
             {
                printf("%ld\n",i);
                flag =1;
                break;
     
             }
        }
            if(flag==0)   printf("No\n");
      
        
}
    return 0;
}
 
#include <stdio.h>
#include <math.h>
int main()
{
    int t,n;
    int i,j;
    int a,b;
    
    while(scanf("%d",&t)!=EOF)
    {
        while(t--)
        { 
            int flag=0;
            scanf("%d",&n);
            for(i=1;i<=10000;i++)
            {
                if((int)sqrt(i*i*n+1)*(int)sqrt(i*i*n+1)==n*i*i+1)
                {
                    printf("%d\n",i);
                    flag=1;
                    break;
                }
            }
            if(flag==0)
            {
                printf("No\n");
            }
        }
    }
    return 0;
}
posted @ 2018-12-25 17:01  菜鸟求大佬  阅读(433)  评论(0编辑  收藏  举报