ZOJ 3483 简单if-else

时间:2022-11-03 12:35:19

提醒:答案要约分,不然会错!

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
const int MAXSIZE = ;
int prime[MAXSIZE];
void init_prim(){
for (int i=;i<MAXSIZE;i++)
prime[i]=;
prime[]=; prime[]=;
for (int i=;i<MAXSIZE;i++){
if (prime[i]==)
for (int j=i*;j<MAXSIZE;j+=i)
prime[j]=;
}
}
int gcd(int a,int b){
return b== ? a : gcd(b,a%b);
}
int main(){
int t,i,j,x1,x2,y1,y2;
int cnt,ans;
init_prim();
scanf("%d",&t);
while(t--){
cnt = ;
ans = ;
scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
for(i=y1;i<=y2;i++){
for(j=x1;j<=x2;j++){
if((i == && j != ) || (i != && j == ))
if((abs(i+j)-) % == && prime[abs(i+j)]) ans++;
if(i != && j != && ((i*i + j*j) - ) % != && prime[i*i + j*j])
ans++;
cnt++;
}
}
//if(ans == 0) cnt = 1;
printf("%d/%d\n",ans/gcd(ans,cnt),cnt/gcd(ans,cnt));
}
return ;
}