Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
7076 | 吴承熹 | 质数的和与积 | C++ | Wrong Answer | 0 MS | 260 KB | 1144 | 2025-04-04 17:01:59 |
#include<iostream> #include<algorithm> using namespace std; int main(){ int s,a,b;//s为题意要求的值,a+b=s int _max=0;//初始化为最小值 cin>>s; for(int i=2;i<=s/2+1;i++){//i只要找到s的一半就可以了 a=i; b=s-a; //判断a是否为质数,如果是则继续判断b是否为质数,如果不是,则结束这一次循环 bool f=true;//标记a为质数,默认true为质数,那么false表示不是质数 for(int j=2;j*j<=a;j++){ if(a%j==0){ f=false; break; } } if(f==false) continue;//如果a不是质数,那么不用判断b了,否则继续判断b f=true;//标记b为质数 for(int j=2;j*j<=b;j++){ if(b%j==0){ f=false; break; } } if(f==true){//如果b也是质数,那么打擂台找最大值 cout<<a<<" "<<b<<" "<<a*b<<endl;//输出每一组质数的积检验一下 _max=max(_max,a*b); } } cout<<_max<<endl; return 0; }
------Input------
6
------Answer-----
9
------Your output-----
3 3 9 9