警示后人,警钟敲炸
  • 板块灌水区
  • 楼主Yeonjun_0913
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/10/19 22:30
  • 上次更新2024/10/20 09:07:40
查看原帖
警示后人,警钟敲炸
1432988
Yeonjun_0913楼主2024/10/19 22:30

关于一道模版题做了6次才AC,全是细节的错误

第一版:

#include <iostream>
using namespace std;

typedef long long ll;
ll a,b,p;
ll q_pow(){
    ll res=1,x=a;
    while (b){
        if (b&1) res=res*x%p;
        x=x*x%p;
        b>>=1;
    }
}

int main (){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> p;
    cout << q_pow();
    return 0;
}

完全没有看题目输出要求


第二版

#include <iostream>
using namespace std;

typedef long long ll;
ll a,b,p;
ll q_pow(){
    ll res=1,x=a%p;
    while (b){
        if (b&1) res=(res*(a%p))%p;
        x=x*x%p;
        b>>=1;
    }
}

int main (){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> p;
    cout << q_pow();
    return 0;
}

跟个小龙虾一样,还没有看见题目输出格式,不知道在瞎调什么


第三版

#include <iostream>
using namespace std;

typedef long long ll;
ll a,b,p;
ll q_pow(){
    ll res=1,x=a%p;
    while (b){
        if (b&1) res=(res*(a%p))%p;
        x=x*x%p;
        b>>=1;
    }
}

int main (){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> p;
    ll ans=q_pow();
    cout << a << "^" << b << ' ';
    cout << "mod" << ' ';
    cout << p << '=';
    cout << ans;
    return 0;
}

此时,这位年轻人终于意识到自己输出格式错了,但他没有发现快速幂被改错了


第四版:

#include <iostream>
using namespace std;

typedef long long ll;
ll a,b,p;
ll q_pow(){
    ll res=1,x=a%p;
    while (b){
        if (b&1) res=(res*(a%p))%p;
        x=x*x%p;
        b>>=1;
    }
    return res;
}

int main (){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> p;
    ll ans=q_pow();
    cout << a << "^" << b << ' ';
    cout << "mod" << ' ';
    cout << p << '=';
    cout << ans;
    return 0;
}

又是像个小龙虾一样,不知道在调什么


第五人格启动版(bushi):

#include <iostream>
using namespace std;

typedef long long ll;
ll a,b,p;
ll q_pow(ll a,ll b,ll p){
    ll res=1,x=a%p;
    while (b){
        if (b&1) res=(res*(a%p))%p;
        x=(x*x)%p;
        b>>=1;
    }
    return res;
}

int main (){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> p;
    cout << b << endl;
    ll ans=q_pow(a,b,p);
    cout << a << "^" << b << ' ';
    cout << "mod" << ' ';
    cout << p << '=';
    cout << ans;
    return 0;
}

自己现在看也不知道当时在调什么


第六版:

#include <iostream>
using namespace std;

typedef long long ll;
ll a,b,p;
ll q_pow(){
    ll res=1,x=a%p;
    ll k=b;
    while (k){
        if (k&1) res=(res*(x%p))%p;
        x=(x*x)%p;
        k>>=1;
    }
    return res;
}

int main (){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> p;
    ll ans=q_pow();
    cout << a << "^" << b << ' ';
    cout << "mod" << ' ';
    cout << p << '=';
    cout << ans;
    return 0;
}

终于AC了

在WA一次我就真的要WA的一声就哭出来了

——违规紫衫

2024/10/19 22:30
加载中...