哥德巴赫猜想散记(蒟蒻文章)

我的一篇半题解文章

https://www.luogu.com.cn/problem/P1304 

哥德巴赫猜想题目链接

这道题应该大部dalao都做过好吧,我这个**蒟蒻**看到这道题二话没说**直接模拟,呵呵,不出所料TLE.....

 我的悲伤世界
https://www.luogu.com.cn/record/157619047

TLE代码和记录

#include<iostream>
#include<fstream>
#include <iomanip>
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int n,s=0,f=0,flag=1;
    cin>>n;
     for(int o=4;o<=n;o+=2){
         flag=1;
         for(int j=2;j<o;j++){
            int m=1;
            for(int i=2;i*i<=j;i++){
                if(j%i==0){
                    m=0;break;
                }    
            }
            if(!m) continue;
            for(int t=j;t<=o-j;t++){
                int k=1;
                for(int g=2;g*g<=t;g++){
                    if(t%g==0){
                        k=0;break;
                    }    
                }
                if(!k) continue;
                if((j+t)==o){
                    cout<<o<<"="<<j<<"+"<<t<<endl;
                    flag=0;break;
                }
            }
            if(flag==0) break;
        }
    }
    

    return 0;
}

显然,我脑子进水了

于是我的亲爱的信息老师让我用递归来做


结果过了
https://www.luogu.com.cn/record/158283627

#include<iostream>
#include<fstream>
#include <iomanip>
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int n,s=0,f=0,flag=1;
    cin>>n;
     for(int o=4;o<=n;o+=2){
         flag=1;
         for(int j=2;j<o;j++){
            int m=1;
            for(int i=2;i*i<=j;i++){
                if(j%i==0){
                    m=0;break;
                }    
            }
            if(!m) continue;
            for(int t=j;t<=o-j;t++){
                int k=1;
                for(int g=2;g*g<=t;g++){
                    if(t%g==0){
                        k=0;break;
                    }    
                }
                if(!k) continue;
                if((j+t)==o){
                    cout<<o<<"="<<j<<"+"<<t<<endl;
                    flag=0;break;
                }
            }
            if(flag==0) break;
        }
    }
    

    return 0;
}


 


总之,听老人言,吃亏在眼前好吧
这句话送给大家


好了,以后有机会再扯淡

  • 12
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值