90分求调
查看原帖
90分求调
754178
leemavis楼主2025/7/31 09:25

一直卡在90分过不去,请各位大佬帮忙看看

#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int m(int n) {
    string s=to_string(n);
    int d=0;
    for(char c:s) d=max(d,c-'0');
    return d;
}

int c(int b,int n) {
    string s=to_string(n);
    reverse(s.begin(),s.end());
    int r=0;
    for(int i=0;i<s.size();++i) r+=(s[i]-'0')*pow(b,i);
    return r;
}

int main() {
    int p,q,r;
    cin>>p>>q>>r;
    
    int t=max({m(p),m(q),m(r)})+1;
    t=max(t,2);
    
    for(int b=t;b<=16;++b) {
        int x=c(b,p),y=c(b,q),z=c(b,r);
        if(x*y==z) {
            cout<<b;
            return 0;
        }
    }
    
    cout<<0;
    return 0;
}

2025/7/31 09:25
加载中...