我做了一道假题?

Kevin_K edited 5 年,11 月前

这道题叫做幂次转换,是2018程序设计能力实训第二次机考的D题,其中有个测试点叫做测试点3,它不大于10^18。
那么,问题来了,为什么这样会哇掉:

#include <bits/stdc++.h>
using namespace std;
typedef long long L;
L po(L x,int y){
    if (y){
        return x*po(x,y-1);
    }
    return 1;
}
bool sol(L x){
    L a,b;
    bool res=0;
    for (int i=2;i<60;i++){
        a=max(2,int(pow(x,1.0/i)));
        b=pow(x,1.0/i)+1;
        for (L j=a;j<=b;j++){
            if (po(j,i)==x){
                cout<<"="<<j<<"^"<<i;
                res=1;
                break;
            }
        }
    }
    return res;
}
int main(){
    int t;
    L x;
    cin>>t;
    while (t--){
        cin>>x;
        cout<<x;
        if (!sol(x)){
            cout<<" is powerless.";
        }
        cout<<endl;
    }
    return 0;
}

这样就AC了:

#include <bits/stdc++.h>
using namespace std;
typedef long long L;
L po(L x,int y){
    if (y){
        return x*po(x,y-1);
    }
    return 1;
}
bool sol(L x){
    L a,b;
    bool res=0;
    for (int i=2;i<61;i++){
        a=max(2,int(pow(x,1.0/i)));
        b=pow(x,1.0/i)+1;
        for (L j=a;j<=b;j++){
            if (po(j,i)==x){
                cout<<"="<<j<<"^"<<i;
                res=1;
                break;
            }
        }
    }
    return res;
}
int main(){
    int t;
    L x;
    cin>>t;
    while (t--){
        cin>>x;
        cout<<x;
        if (!sol(x)){
            cout<<" is powerless.";
        }
        cout<<endl;
    }
    return 0;
}

用命分析一波:
两个代码的区别在于指数能不能是60(即i=60),如果可以是60,根据题意,那至少有个数大于等于2^60(因为一个哇掉一个AC所以这个数肯定存在!),2^60=1,152,921,504,606,846,976>10^18。
???
我做了假题,还是我这个人就是假的?由于哇了一个小时18发,我已经失去了理智,求大佬指点。

Comments

zerol

我数据没出好,测试点 3 中有一组 $2^{60}$ 超出了数据范围,实在是抱歉。

Kevin_K

emmmm…不知道为什么我现在莫名想笑,哈哈哈。
~~还好没报这次考试。~~

10175101159

惨呐
我没想那么多
就直接上64得了2333

Kevin_K

强迫症患者表示感受到了这个世界深深的恶意.(滑稽2333)