标签:style http color width os for
题目大意:给出一个a,b,表示高斯数a+bi(i=?2 ̄ ̄ ̄√,判断该数是否为高斯素数。
解题思路;
#include <cstdio>
#include <cstring>
#include <cmath>
bool is_prime (int n) {
int m = sqrt(n+0.5);
for (int i = 2; i <= m; i++)
if (n % i == 0)
return false;
return true;
}
bool judge (int a, int b) {
if (a == 0)
return false;
return is_prime(a*a+2*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 0;
}
uva 1415 - Gauss Prime(高斯素数),布布扣,bubuko.com
标签:style http color width os for
原文地址:http://blog.csdn.net/keshuai19940722/article/details/36866219