盘点一些弱智代码

P1001 A+B Problem

wyp20130701 @ 2024-10-14 20:41:21

正常版:

#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
    return 0;
}

弱智度:40%:

#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    for (int i = 1;i <= b;i++)
    {
        a++;
    }
    cout << a << endl;
    return 0;
}

弱智度 70%:

#include <iostream>
using namespace std;
int main()
{
    long long a,b;
    cin >> a >> b;
    for (int i = 1;;i++)
    {
        if (i == a + b)
        {
            cout << i;
            break;
        }
    }
    return 0;
}

弱智度 999999%:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    srand(time(0));
    int a,b;
    cin >> a >> b;
    int ans = rand();
    if (ans == a + b)
    {
        cout << ans << endl;
    }
    else
    {
        while (ans != a + b)
        {
            ans = rand();
        }
        cout << ans << endl;
    }
    return 0;
}

by crz_qwq @ 2024-10-14 20:42:39

更加好笑的点:源代码-C


by Civilight_Eterna @ 2024-10-14 20:48:02

https://www.luogu.com.cn/record/182145647


by Civilight_Eterna @ 2024-10-14 20:48:31

https://www.luogu.com.cn/record/145590979


by 3_14 @ 2024-10-14 20:48:59

6


by Cczzyy20150005 @ 2024-10-14 20:52:39

你这算啥,看我杜教筛

#include<bits/stdc++.h>
using namespace std;
#define int long long
int rd(int x=0,char c=getchar()){int f=1;while(!isdigit(c))f=(c^'-'?1:-1),c=getchar();while(isdigit(c))x=x*10+(c^48),c=getchar();return x*f;}
const int N=1e6+3;
int phi[N],mu[N],p[N],k,pr[N];
int sm[N];
void init(){
    phi[1]=1;sm[1]=1;mu[1]=1;
    for(int i=2;i<N;i++){
        if(!p[i])p[i]=i,phi[i]=i-1,pr[++k]=i,mu[i]=-1;
        for(int j=1;j<=k&&i*pr[j]<N;j++){
            p[i*pr[j]]=pr[j];
            if(pr[j]==p[i]){phi[i*pr[j]]=phi[i]*pr[j],mu[i*pr[j]]=0;break;}
            else phi[i*pr[j]]=phi[i]*phi[pr[j]],mu[i*pr[j]]=-mu[i];
        }
        sm[i]=sm[i-1]+i;
    }for(int i=1;i<N;i++)phi[i]+=phi[i-1],mu[i]+=mu[i-1];
}
unordered_map<int,int> sid,sphi,smu;
int get_phi(int x){
    if(x<N)return phi[x];
    if(sphi.count(x))return sphi[x];
    int sum=(x+1)*x/2;
    for(int l=2,r;l<=x;l=r+1){r=x/(x/l);sum-=(r-l+1)*get_phi(x/l);}return sphi[x]=sum;
}
int get_mu(int x){
    if(x<N)return mu[x];
    if(smu.count(x))return smu[x];
    int sum=1;
    for(int l=2,r;l<=x;l=r+1){r=x/(x/l);sum-=(r-l+1)*get_mu(x/l);}return smu[x]=sum;
}
int solve(int x){
    if(x<N)return sm[x];
    if(sid.count(x))return sid[x];
    int ans=get_phi(x);
    for(int l=2,r;l<=x;l=r+1){
        r=x/(x/l);
        ans-=(get_mu(r)-get_mu(l-1))*solve(x/l);
    }return sid[x]=ans;
}
signed main(){
    int a=rd(),b=rd();init();
    int fla=1,flb=1;
    if(a<0)fla=-1,a=-a;
    if(b<0)flb=-1,b=-b;
    cout<<fla*(solve(a)-solve(a-1))+flb*(solve(b)-solve(b-1));  
    return 0;
}

by guoyichen_guoyichen @ 2024-10-14 20:59:53

弱智度 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999%:

#include<bits/stdc++.h>

using namespace std;

struct node{
    long long l,r;
    long long sum;
    long long lazy; 
}t[2000020 * 4];

long long a[2000020];

void update(long long i)
{
    t[i].sum = t[i << 1].sum + t[i << 1|1].sum;
}

void pushdown(long long i)
{
    t[i<<1].lazy += t[i].lazy;
    t[i<<1|1].lazy += t[i].lazy;

    t[i<<1].sum += (t[i<<1].r - t[i<<1].l+1) * t[i].lazy;
    t[i<<1|1].sum += (t[i<<1|1].r - t[i<<1|1].l+1) * t[i].lazy;

    t[i].lazy = 0;
    update(i);
}

void build_tree(long long i,long long l,long long r)
{
    t[i].l = l;
    t[i].r = r;
    if(l == r)
    {
        t[i].sum = a[l];
        return ;    
    }
    long long mid = (l + r) / 2;
    build_tree(i * 2,l,mid);
    build_tree(i * 2 + 1,mid + 1,r);
    update(i);
}

long long query(long long i,long long l,long long r)//在i这个节点内查询 l 到 r 的值
{
    if(r < t[i].l || l > t[i].r)
        return 0;
    if(l <= t[i].l && t[i].r <= r)
        return t[i].sum;

    pushdown(i);
    return query(i<<1,l,r) + query(i<<1|1,l,r);
}
int main()
{
//  freopen("test.in","r",stdin);
//  freopen("test.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n,m;
    n = 2,m = 1;
    cin >> a[1] >> a[2];
    build_tree(1,1,n);
    long long l,r;
    l = 1,r = 2;
    cout << query(1,l,r) << endl;
    return 0;
}

by I2147483647I @ 2024-10-15 21:51:42

4个是在买彩票吗......


by Naszt @ 2024-10-16 17:18:44

@Cczzyy20150005

利用 id*\mu=\varphi 反向求 id 是吧,妙(


by Cczzyy20150005 @ 2024-10-16 20:00:38

@Naszt 遇到同道中人了。


by XCH66666 @ 2024-10-19 09:24:20

@xionghaoran123 第2个可以吗?怎么有中文


| 下一页