数学专项number_theory:LA 4079
来源:互联网 发布:汤不热同类软件 编辑:程序博客网 时间:2024/05/22 00:23
学过复变函数的都知道,复数可以由模乘上辐角来表示。所以不难得出当a*a+2*b*b为素数时,该数为高斯素数。但是还得考虑a或b为0的情况,这里我用了枚举的方法,若a或b能表示为x*x+2*y*y的形式且为为素数时,该数也为高斯素数。
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int isprime(int x){ int m=sqrt(x*1.0); for(int i=2;i<=m;i++) if(x%i==0) return 0; return 1;}int judge(int x){ int m=sqrt(x*1.0); for(int i=0;i<=m;i++) { double t=sqrt((x-i*i*1.0)/2.0); if(ceil(t)==floor(t)) return 1; } return 0;}int main(){ int T; cin>>T; while(T--) { int a,b; cin>>a>>b; if(abs(a)<=1&&b==0) {cout<<"No"<<endl;continue;} if(a==0) { if(isprime(abs(b))&&!judge(abs(b))) cout<<"Yes"<<endl; else cout<<"No"<<endl; continue; } if(b==0) { if(isprime(abs(a))&&!judge(abs(a))) cout<<"Yes"<<endl; else cout<<"No"<<endl; continue; } int t=a*a+2*b*b; if(!isprime(t)) cout<<"No"<<endl; else cout<<"Yes"<<endl; } return 0;}
- 数学专项number_theory:LA 4079
- 数学专项number_theory:LA 2955
- 数学专项number_theory:LA 3262
- 数学专项number_theory:LA 3521
- 数学专项number_theory:LA 4382
- 数学专项number_theory:UVa 10515
- 数学专项number_theory:UVa 10622
- 数学专项number_theory:UVa 10127
- 数学专项number_theory:UVa 10090
- 数学专项number_theory:UVa 10539
- 数学专项number_theory:UVa 11105
- 数学专项number_theory:UVa 11490
- 数学专项number_theory:UVa 11728
- 数学专项number_theory:UVa 10692
- 数学专项number_theory:UVa 10951
- 数学专项number_theory:UVa 756
- 数学专项number_theory:UVa 718
- 数学专项number_theory:UVa 294
- 公民的身份证号码检测
- 【task】Android终止线程
- 空间RESUMABLE操作 (ora-01536、ora-06512)
- 0500
- Ogre粒子编辑器ParticleUniverse
- 数学专项number_theory:LA 4079
- 通过数据库存储过程调用Web服务的办法
- WINDOWS 逻辑坐标 设备坐标 屏幕坐标 客户区坐标
- ContentObserver +loader+CursorAdapter解释
- 当你输入信用卡号码的时候,有没有担心输错了而造成损失呢?其实可以不必这么担心,因为并不是一个随便的信用卡号码都是合法的,它必须通过Luhn算法来验证通过。 该校验的过程:1、从卡号最后一位数字开始,逆
- JSP自定义标签(select)
- Android中ListView的性能问题
- 嵌入式车载平台的GPRS网络实现-续PPP协议(转)
- 1007. Maximum Subsequence Sum (25)-PAT