先上题目:

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. 在ubuntu中安装photoshop cs6

    对于很多专业的PS高手来说,真心难以找到顺手的且可以完美替代PS的软件,所以我们这里的解决办法就是用wine来安装. 虽然网上有很多的wine安装ps的方法,但是在使用过程往住会发生莫名其妙的崩溃,体 ...

  2. 修改input:file样式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  3. B1024 生日快乐 递归。。。

    bzoj1024叫生日快乐,其实很简单,但是没看出来就很尴尬... Description windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕.现在包括win ...

  4. PCB 奥宝LDI 输出自动改周期检测内容

    继续完善奥宝LDI输出,在自动更新周期发现前期梳理不过完善或出些从未考虑到的工艺问题, 今天将更改线路周期检测内容整理如下

  5. Windows<小白>详细笔记

    Windows 7 部署 =========================================== ========================================== ...

  6. ruby --Paperclip::NotIdentifiedByImageMagickError

    首先,如果遇到这个问题,Paperclip::NotIdentifiedByImageMagickError,先检查下环境变量是否配置了ImagicMagick的路径. cmd下path 查看,首先加 ...

  7. Vue跨域访问,axios&cors

    先安装node.js和npm,这个不用说了,直接在创建vue项目,然后实践一下跨域访问. 如果npm安装较慢,可安装淘宝镜像,执行下面命令: npm install -g cnpm --registr ...

  8. 自学Python五 爬虫基础练习之SmartQQ协议

    BAT站在中国互联网的顶端,引导着中国互联网的发展走向...既受到了多数程序员的关注,也在被我们所惦记着... 关于SmartQQ的协议来自HexBlog,根据他的博客我自己也一步一步的去分析,去尝试 ...

  9. 省市区县的sql语句——省

    /*SQLyog v10.2 MySQL - 5.5.48 : Database - 省市县****************************************************** ...

  10. Haar、pico、npd、dlib等多种人脸检测特征及算法结果比较

    原文:opencv.pico.npd.dlib.face++等多种人脸检测算法结果比较 NDP检测结果: 结果分析: Pico(Pixel Intensity Comparison-based Obj ...