題目連結:uva 1415 - Gauss Prime
題目大意:給出一個a,b,表示高斯數a+bi(i=−2‾‾‾√,推斷該數是否為高斯素數。
解題思路;
- a = 0 時。肯定不是高斯素數
- a != 0時,推斷a2+2b2是否為素數就可以。
#include <cstdio>
#include <cstring>
#include <cmath>
bool is_prime (int n) {
int m = sqrt(n+);
for (int i = ; i <= m; i++)
if (n % i == )
return false;
return true;
}
bool judge (int a, int b) {
if (a == )
return false;
return is_prime(a*a+*b*b);
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
int a, b;
scanf("%d%d", &a, &b);
printf("%s\n", judge(a, b) ?
"Yes" : "No"); } return ; }
轉載于:https://www.cnblogs.com/lcchuguo/p/5128654.html