先上题目:

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

最新文章

  1. UVA1368
  2. phantomjs 双向认证,访问nginx,https
  3. 【C#】分享带等待窗体的任务执行器一枚
  4. 使用Apache Bench进行压力测试
  5. Tiny PXE Server简介
  6. Facade模式
  7. 对Javascript异步执行的理解
  8. HDU ACM 1495 非常可乐(广搜BFS)
  9. h5drag事件
  10. ASP.NET MVC 分页问题
  11. Object.keys、Object.getOwnPropertyNames区别
  12. PhoneGap安装手顺
  13. Codeforces 250 E. The Child and Binary Tree [多项式开根 生成函数]
  14. 利用XPT2046制作一个电位器AD转换装置
  15. 剑指offer——python【第59题】按之子形顺序打印二叉树
  16. 使用Tensoflow实现梯度下降算法的一次线性拟合
  17. bzoj千题计划295:bzoj3140: [Hnoi2013]消毒
  18. metasploit渗透测试指南概要整理
  19. 服务发现 consul cluster 的搭建
  20. Codeforces Round #350 (Div. 2) C. Cinema 水题

热门文章

  1. 通过指针访问C++对象的私有成员
  2. DBI(i80)/DPI(RGB)/DSI【转】
  3. C# Socket 您的主机中的软件中止了一个已建立的连接 An established connection was aborted by the software in your host machine
  4. C#遍历DataSet与DataSet元素实现代码
  5. bzoj4078
  6. Python 35 线程(1)线程理论、开启线程的两种方式
  7. 用 Django2.0 做 简单的BBS(前端用 Bootstrap)
  8. MyEclipse创建SSH项目(Java web由maven管理)
  9. JavaScript的基本语法(一)
  10. 两款工作流JBPM和CCBPM的对比