先上题目:

Gaussian Prime


Time Limit: 3 Seconds      Memory Limit: 65536 KB

In number theory, a Gaussian integer is a complex number whose real and imaginary part are both integers. The Gaussian integers, with ordinary addition and multiplication of complex numbers, form an integral domain, usually written as Z[i]. The prime elements of Z[i] are also known as Gaussian primes. Gaussian integers can be uniquely factored in terms of Gaussian primes up to powers of i and rearrangements.

A Gaussian integer a + bi is a Gaussian prime if and only if either:

  • One of ab is zero and the other is a prime number of the form 4n + 3 (with n a nonnegative integer) or its negative -(4n + 3), or
  • Both are nonzero and a2 + b2 is a prime number (which will not be of the form 4n + 3).

0 is not Gaussian prime. 1, -1, i, and -i are the units of Z[i], but not Gaussian primes. 3, 7, 11, ... are both primes and Gaussian primes. 2 is prime, but is not Gaussian prime, as 2 =i(1-i)2.

Your task is to calculate the density of Gaussian primes in the complex plane [x1x2] × [y1y2]. The density is defined as the number of Gaussian primes divided by the number of Gaussian integers.

Input

There are multiple test cases. The first line of input is 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, output the answer as an irreducible fraction.

Sample Input

3
0 0 0 0
0 0 0 10
0 3 0 3

Sample Output

0/1
2/11
7/16

References

  题意:告诉你一种数的定义,这种数是一个复数,告诉你题目的整个区间的范围,然后给你一个区间,问这个区间里面这种数的密度是多少(这种数比上区间里面的数的总个数)?

  题目给的范围比较小,所以可以先预处理把区间里面的这种数都标记出来,然后对于每一次询问就搜一次。

  这题需要注意的地方是这种数的定义。这里现需要把0~20000的素数都筛出来,然后根据定义把区间的这种数都找出来就行了。

  还有一个需要注意的地方是如果分子是零的时候需要输出的是0/1,而不是0/大于1的分母。

上代码:

 #include <cstdio>
#include <cstring>
#define MAX 20002
#define LL long long
using namespace std; bool f[MAX]; void deal(){
LL n=MAX-;
f[]=f[]=;
memset(f,,sizeof(f));
for(LL i=;i<=n;i++){
if(!f[i]){
for(LL j=i*i;j<=n;j+=i){
f[j]=;
}
}
}
} bool s[][]; bool check(int y,int x){
if(y== && x==) return ;
else if((y== && x!= )|| (y!= && x==)){
int k=x+y;
if(k<) k=-k;
if(k%==%){
return !f[k];
}
return ;
}else{
LL sum=y*y+x*x;
if(!f[sum] && (sum-+)%!=) return ;
//if(!f[sum]) return 1;
}
return ;
} void work(){
int y,x;
for(int i=;i<=;i++){
for(int j=;j<=;j++){
y=i-;
x=j-;
if(check(y,x)) s[i][j]=;
}
}
} int gcd(int a,int b){
return b== ? a : gcd(b,a%b);
} void ask(){
int a,b,c,d,g;
int pr,num;
scanf("%d %d %d %d",&a,&b,&c,&d);
a+=;
b+=;
c+=;
d+=;
pr=;
num=;
for(int i=a;i<=b;i++){
for(int j=c;j<=d;j++){
if(s[i][j]) pr++;
num++;
}
}
g=gcd(num,pr);
printf("%d/%d\n",pr/g,num/g);
} int main()
{
int t;
//freopen("data.txt","r",stdin);
deal();
work();
scanf("%d",&t);
while(t--){
ask();
}
return ;
}

3483

ZOJ - 3483 - Gaussian Prime的更多相关文章

  1. ZOJ 3483 简单if-else

    提醒:答案要约分,不然会错! #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  2. ZOJ 3707 Calculate Prime S 数论

    思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: ...

  3. 2019/10/27 TZOJ

    1001 Gaussian Prime http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=379 ...

  4. ZOJ 1457 Prime Ring Problem(dfs+剪枝)

     Prime Ring Problem Time Limit: 10 Seconds      Memory Limit: 32768 KB A ring is compose of n circ ...

  5. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  6. Prime Query (ZOJ 3911 线段树)

    Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a sequen ...

  7. ZOJ 3911 Prime Query ZOJ Monthly, October 2015 - I

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  8. ZOJ 3911 Prime Query(线段树)

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  9. ZOJ 2015 10月份 月赛 3911 Prime Query

    这道题我改啊,改啊,交啊,就对了. #include <stdio.h> #include <stdlib.h> #include <math.h> #includ ...

随机推荐

  1. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  2. Android 6.0 中TimePicker显示为滚动样式的方法

    在Android6.0中,TimePicker控件的默认样式为转盘的样式,就像这个样子: 如果想要显示为之前的滚动样式的话也很简单,只要在布局文件中设置TimePicker的timePickerMod ...

  3. U32670 小凯的数字 数学

    这是洛谷一个比赛中的一道题,和去年NOIP D1T1挺像.我看了一眼之后想“这不是小学奥数吗?求一个数字和就好了呀”...然后,60,剩下T了,gg. 只好看正解,但是一脸懵逼???然后看了证明,c* ...

  4. 第7章 Android中访问网络资源

    http://developer.android.com/index.html->https://developer.android.com/index.html https://develop ...

  5. Aspnet_Session

    cmd: aspnet_regsql.exe -ssadd -sstype c -d ZZCasSession -S 192.168.0.3 -U sa -P szhweb2010 <!--会话 ...

  6. Ubuntu中在终端进入root权限但是总提示密码错误的解决方案

    先解除root锁定,为root用户重新设置密码 打开终端输入:sudo passwd(注意是passwd不是password) Password: <--- 输入你当前用户的密码 Enter n ...

  7. “发布后tomcat中的classes目录为空”问题

    办法:Project-clean,ok,问题解决.

  8. 【Oracle】详解10053事件

    借助Oracle的10053事件event,我们可以监控到CBO对SQL进行成本计算和路径选择的过程和方法. 10053事件有两个级别: Level 2:2级是1级的一个子集,它包含以下内容: Col ...

  9. C#设置开机启动项、取消开机启动项

    如果想你写的程序随系统开机一起启动的话,那么你可以照下面这个方法来做. RunWhenStart(false, Application.ProductName, Application.Startup ...

  10. javaee Properties键值对写入和读取方法

    package Zjshuchu; import java.util.Properties; import java.util.Set; public class Demo03 { public st ...