zstuACM 问题 G: 深入浅出学算法007-求佩尔方程的解

http://47.96.116.66/problem.php?cid=3252&pid=6

x^2 - n*y^2 = 1 可化为 x^2 = n*y^2 + 1,然后可以忽略x,用(sqrt(1+n*y*y)) * (sqrt(1+n*y*y)) = 1+n*y*y来判断1+n*y*y是否是平方数即可。
#include
#include
#define LL long long
using namespace std;
int main(){
int t;cin>>t;
while(t--){
int n;cin>>n;
bool flag=true;
for(LL y=1;y<=10000;y++){ if( (int)(sqrt(1+n*y*y))*(int)(sqrt(1+n*y*y))==1+n*y*y ){ flag=fals

zstuACM 问题 G: 深入浅出学算法007-求佩尔方程的解最先出现在Python成神之路

版权声明:
作者:admin
链接:https://www.techfm.club/p/4800.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>