码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 1415 Gauss Prime

时间:2014-08-26 11:46:25      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   os   io   for   ar   div   

Description

bubuko.com,布布扣

In the late 1700s‘, Gauss, a famous mathematician, found a special kind of numbers. These integers are all in the form: a + bbubuko.com,布布扣 .The sum and multiplication ofthese integers can be naturally defined as the follows:


(a + bbubuko.com,布布扣) + (c + dbubuko.com,布布扣) = (a + c) + (b + d )bubuko.com,布布扣


(a + bbubuko.com,布布扣) * (c + dbubuko.com,布布扣) = (a*c = b*d*k) + (a*d + b*c)bubuko.com,布布扣


One can prove that the sum and multiplication of these integers constitute the structure called ``imaginary quadratic field" in calculus.

In case k = 1 , these are common complex numbers.

In case both a and b are integers, these numbers are called ``Gauss integers", and this is the very case that interests people the most in quadratic algebra.

As we all know that every integer can be factorized into the multiplication of several primes (Fundamental theoorem of arithmetic, or unique factorization theorem).

Primes are the integers that can only be divided by 1 and itself. We do have a similar concept in the context ofGauss integer.

If a Gauss integer cannot bee factorized into the multiplication of other Gauss integers (0, 1, -1 exclusive), we call it a ``Gauss Prime" or ``Non-divisible".

Please note that 0, 1 and - 1 are not regarded as gauss primes but bubuko.com,布布扣 is.

However, unique factorization theorem doesn‘t apply to arbitrary k . For example in the case k = 5 , 6 can be factorized in two different ways: 6 = 2 * 3, 6 = (1 + bubuko.com,布布扣) * (1 - bubuko.com,布布扣) .

Thanks to the advance of mathematics in the past 200 years, one can prove that there are only 9 integers can be used as k , such that the unique factorization theorem satisfies. These integers are k = { 1, 2, 3, 7, 1 1, 19, 43, 67, 163}.

Input 

The first line of the input is an integer n(1 < n < 100) , followed by n lines. Each line is a single case and contains two integers, a and b(0bubuko.com,布布扣abubuko.com,布布扣10000, 0 < bbubuko.com,布布扣10000) .

Output 

To make this problem not too complicated, we just suppose that k is 2.

For every case of the input, judge whether a + bbubuko.com,布布扣 is a gauss prime.

Output the answer `Yes‘ or `No‘ in a single line.


Sample Explanation

Please notes that (5, 1) is not a gauss prime because (5, 1) = (1, -1) * (1, 2) .

Sample Input 

2
5  1
3  4

Sample Output 

No
Yes
题意:求一个高斯整数是不是高斯素数
思路:当a=0或者b=0的时候,不是素数;当a!=0的时候,看a^2+2*b^2是不是素数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std;

int main() {
	int t, a, b;
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d", &a, &b);
		if (b == 0)
			printf("No\n");
		else {
			if (a == 0)
				printf("No\n");
			else {
				int flag = 0;
				ll x = a*a + 2*b*b;
				for (int i = 2; i <= sqrt(x+0.5); i++) 
					if (x % i == 0) {
						printf("No\n");
						flag = 1;
						break;
					}
				if (!flag)
					printf("Yes\n");
			}
		}
	}
	return 0;
}

 

UVA - 1415 Gauss Prime

标签:des   style   http   color   os   io   for   ar   div   

原文地址:http://blog.csdn.net/u011345136/article/details/38843797

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!