UVA - 1415 Gauss Prime

Description

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

(a + b) + (c +
d) = (a +
c) + (b + d )

(a + b)
* (c + d) = (a*c =
b*d*k) + (a*d +
b*c)

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
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 + )
* (1 - ) .

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(0a10000,
0 < b10000) .

Output

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

For every case of the input, judge whether a +
b
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;
}

时间: 2024-10-07 09:49:07

UVA - 1415 Gauss Prime的相关文章

uva 1415 - Gauss Prime(高斯素数)

题目链接: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+0.5); for (int i = 2;

UVA 1415 - Gauss Prime(数论,高斯素数拓展)

UVA 1415 - Gauss Prime 题目链接 题意:给定a + bi,推断是否是高斯素数,i = sqrt(-2). 思路:普通的高斯素数i = sqrt(-1),推断方法为: 1.假设a或b为0.推断还有一个数为4 * n + 3形式的素数(用到费马平方和定理) 2.假设a.b都不为0,推断a ^ 2 + b ^ 2 是否为素数 那么这题,提取出sqrt(2)来,就和基本情况一样了. 对于2,变成: 假设a.b都不为0,推断a ^ 2 + 2 b ^ 2是否为素数 对于1.事实上仅仅

uva 11610 Reverse Prime

Problem FReverse Prime Input: Standard Input Output: Standard Output There are a few 7 digit positive numbers whose reverse number is a prime number and less than 10^6.  For example: 1000070, 1000090 and 1000240 are first few reverse prime numbers be

uva 10539 - Almost Prime Numbers(数论)

题目链接:uva 10539 - Almost Prime Numbers 题目大意:给出范围low~high,问说在这个范围内有多少个数满足n=pb,(p为素数). 解题思路:首先处理出1e6以内的素数,然后对于每个范围,用solve(high)?solve(low?1),solve(n)用来处理小于n的满足要求的数的个数.枚举素数,判断即可. #include <cstdio> #include <cstring> typedef long long ll; const int

uva 10780 Again Prime? No Time. 质因子乱搞

求最大的k   使得 m^k 能被n!整除 m^k就是让m的每个质因子个数增加了k倍,只要求得n!的质因子能让m增加多少倍就够了.当然这里要取增加倍数最少的. 木桶装水的量取决于最短的木板. 预处理2-n每个数的质因子情况,由于n有10000,前10000个素数有1000+个,所以维护前缀和不划算. case只有500 所以干脆每次都算一遍. #include<stdio.h> #include<string.h> #include<iostream> #include

uva 10780 Again Prime? No Time.

POINT : 质因子分解:(仅给题解) http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1721 题意:给你两个整数m和n,求最大的k使得m^k是n!的约数 思路:首先我们先将m分解质因数,那么m^k就是各个质因数*k而已,那么我们只要判断每个质因数的指数在n!的对应的质因数的指数范围内,求所有质因数最小的一

UVA - 10780 Again Prime? No Time. (质因子分解)

Description Again Prime? No time. Input: standard input Output: standard output Time Limit: 1 second The problem statement is very easy. Given a number n you have to determine the largest power of m, not necessarily prime, that divides n!. Input The

UVA - 10539 Almost Prime Numbers (几乎是素数)

题意:输入两个正整数L.U(L<=U<1012),统计区间[L,U]的整数中有多少个数满足:它本身不是素数,但只有一个素因子. 分析: 1.满足条件的数是素数的倍数. 2.枚举所有的素数,以及其倍数,将满足条件且小于等于n的个数计算出来,solve(u) - solve(l - 1)即可. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cst

UVA 10539 Almost Prime Numbers( 素数因子)

Problem AAlmost Prime NumbersTime Limit: 1 second Almost prime numbers are the non-prime numbers which are divisible by only a single prime number. In this problem your job is to write a program which finds out the number of almost prime numbers with