先上题目:

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. 修改input:file样式

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

  2. elasticsearch _field_stats 源码分析

    _field_stats 实现的功能:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-field-stats.ht ...

  3. bzoj3110 [Zjoi2013]K大数查询——线段树套线段树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3110 外层权值线段树套内层区间线段树: 之所以外层权值内层区间,是因为区间线段树需要标记下传 ...

  4. android有用代码片段

    一.  获取系统版本号: [java] view plaincopy PackageInfo info = this.getPackageManager().getPackageInfo(this.g ...

  5. sqlserver导入数据到mysql的详细图解

    SQL Server 迁移数据到MySQL 一.背景 由于项目开始时候使用的数据库是SQL Server,后来把存储的数据库调整为MySQL,所以需要把SQL Server的数据转移到MySQL:由于 ...

  6. jq中append()、prepend()、after()、before()的区别

    jq中append().prepend().after().before()的区别详解 .append() - 在被选元素的结尾插入内容(内容的结尾,比如说有个a标签,则是在</a>这个标 ...

  7. EasyUI DataGrid组织事件冒泡

    在事件内部需要阻止的地方添加如下代码 ]; 解释: arguments.callee是获得我自定义的事件处理方法OnSelected的方法体. .caller是获得调用OnSelected的上层方法( ...

  8. JQuery 动态创建表单,并自动提交

    前言:写这个是为了实现使用cookie进行自动登录的功能, 下面的代码是一个元素一个元素进行创建和赋值的, (可以尝试下将所有的html代码(form.input)全部拼好以后放到${ } 中,再进行 ...

  9. 设置Hadoop的 dataNode的单个Map的内存配置

    1.进入hadoop的配置目录 ,找到 环境变量的 $HADOOP_HOME cd $HADOOP_HOME 2.修改dataNode 节点的 单个map的能使用的内存配置 找到配置的文件: /opt ...

  10. vs2015网站部署到iis后运行调试:无法在web服务器上启动调试的问题,403已禁止

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Frame ...