寻找素数对

哥德巴赫猜想大家都晓得一点吧.咱们当初不是想证实这个论断,而是想在程序语言外部可能示意的数集中,任意取出一个偶数,来寻找两个素数,使得其和等于该偶数.
做好了这件实事,就能阐明这个猜测是成立的.
因为能够有不同的素数对来示意同一个偶数,所以专门要求所寻找的素数对是两个值最相近的.
Input
输出中是一些偶整数M(5<M<=10000).
Output
对于每个偶数,输入两个彼此最靠近的素数,其和等于该偶数.
Sample Input
20 30 40
Sample Output
7 13
13 17
17 23

//(数论素数(欧拉筛,埃氏筛)#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<cstdio>#include<queue>#include<stack> #include<set> #include<vector> using namespace std;int n,a[10005];//标记数组 int main(){    for(int i = 1; i <= 10000; i++){//打表标记素数标记数组a[],1示意是素数,0代表不是         a[i] = 1;        for(int j = 2; j * j <= i; j++){            if(i % j == 0){                a[i] = 0;                break;            }        }    }    while(scanf("%d",&n) != EOF){        for(int i = n/2; i > 0; i--){//从两头向两边开始遍历,第一个无效素数对的两个值肯定最相进             if(a[i] == 1 && a[n - i] == 1){                printf("%d %d\n",i,n - i);                break;             }        }    }     return 0;} 

a/b + c/d

给你2个分数,求他们的和,并要求和为最简模式。
Input
输出首先蕴含一个正整数T(T<=1000),示意有T组测试数据,而后是T行数据,每行蕴含四个正整数a,b,c,d(0<a,b,c,d<1000),示意两个分数a/b 和 c/d。
Output
对于每组测试数据,输入两个整数e和f,示意a/b + c/d的最简化后果是e/f,每组输入占一行。
Sample Input
2
1 2 1 3
4 3 2 3
Sample Output
5 6
2 1

//(数论(最大公约数gcd()最小公倍数lcm()) #include<iostream>#include<algorithm>#include<string>#include<string.h>#include<cstdio>#include<queue>#include<stack> #include<set> #include<vector> using namespace std;int gcd(int a,int b){    if(b == 0){        return a;    }    return gcd(b,a % b);}int main(){    int t = 0;    cin >> t;    int a,b,c,d;    int e,f;    while(t--){        scanf("%d%d%d%d",&a,&b,&c,&d);        e = a*d + b*c;        f = b*d;//        printf("%d %d\n",(int)(e / gcd(e,f)),(int)(f / gcd(e,f)));        printf("%d %d\n",e / gcd(e,f),f / gcd(e,f));    }    return 0;}