Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4280
In number theory, a Gaussian integer was a complex number whose real and imaginary part is both integers. The Gaussian integers, with ordinary addition and multiplication of complex numbers, form an integral domain, usually writ Ten as Z[i]. The prime elements of Z[i] are also known as Gaussian primes. Gaussian integers can is uniquely factored in terms of Gaussian primes up to powers of I and rearrangements.
A Gaussian integer a + b i is a Gaussian the prime if and only if either:
- One a of, is zero and the other are a prime number of the b Form 4 n + 3 (with n a nonnegative integer) or its n Egative-(4 n + 3), or
- Both was nonzero and 2 + 2 is a prime number (which would not be of the of the a b Form 4 n + 3).
0 is not Gaussian prime. 1,-1, I, and-I are is the units of Z[i], but not Gaussian primes. 3, 7, one, ... are both primes and Gaussian primes. 2 is prime, and is not Gaussian prime, as 2 = I(1-i) 2.
Your task is to calculate the density of Gaussian primes in the complex plane [ x1 , x2 ]x[ y1 , y2 ]. T He density is defined as the number of Gaussian primes divided by the number of Gaussian integers.
Input
There is multiple test cases. The first line of input was an integer T ≈100 indicating the number of test cases.
Each test case consists of a line containing 4 integers-100≤ x1 ≤ x2 100, -100≤ y1 ≤ y2 ≤100.
Output
For each test case, the output of the answer as an irreducible fraction.
Sample Input
30 0 0 00 0 0 100 3 0 3
Sample Output
0/12/117/16
References
- Http://en.wikipedia.org/wiki/Gaussian_integer
- Weisstein, Eric W. "Gaussian Prime." From MathWorld--a Wolfram Web Resource. Http://mathworld.wolfram.com/GaussianPrime.html
The code is as follows:
#pragma warning (disable:4786) #include <cstdio> #include <cmath> #include <cstring> #include < string> #include <cstdlib> #include <climits> #include <ctype.h> #include <queue> #include <stack> #include <vector> #include <utility> #include <deque> #include <set> #include < map> #include <iostream> #include <algorithm>using namespace std;const double eps = 1e-9;//const double pi = Atan (1.0) *4;const double pi = 3.1415926535897932384626;const Double e = exp (1.0); #define INF 0x3f3f3f3f//#define INF 1E18 typedef long Long ll;//typedef __int64 LL; #define ONLINE_JUDGE#IFNDEF online_judgefreopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout), #endif # define MAXN 100000int prim[maxn];void init () {for (int i = 2; I <= maxn; i++) {if (!prim[i]) {for (int j = i+i; J <= Maxn; j+=i) {prim[j] = 1; }}}}int GCD (int a, int b) {if (b = = 0) return A; Return GCD (b,a%b);} int main () {int t; Init (); scanf ("%d", &t); int x1, x2, y1, y2; while (t--) {cin>>x1>>x2>>y1>>y2; int ans = 0; int tem; for (int x = x1; <= x2; x + +) {for (int y = y1; y <= y2; y++) {if (x = = 0) {if (Y < 0) {tem =-y; } else tem = y; if ((tem-3)%4==0 && prim[tem]==0) ans++; } else if (y = = 0) {if (x < 0) { TEM =-X; } else tem = x; if ((tem-3)%4==0 && prim[tem]==0) ans++; } else {tem = X*x+y*y; if (prim[tem]==0 && (tem-3)%4!=0) ans++; }}} int tol = (x2-x1+1) * (y2-y1+1); int gcd = GCD (Ans,tol); printf ("%d/%d\n", ANS/GCD,TOL/GCD); } return 0;}
ZOJ 3483 Gaussian Prime (math AH)