ABC166 D - I hate Factorization(数学,枚举)

题意:

在这里插入图片描述

解法:

f(x)=x^5

f(n)-f(n-1)>1e9,
n不需要太大就能满足条件(几百就够了),
因此直接[-200,200]枚举A和B即可.

code:

#include<bits/stdc++.h>
#define int long long
#define PI pair<int,int>
using namespace std;
const int maxm=2e6+5;

int f(int x){
    
    
    return x*x*x*x*x;
}
void solve(){
    
    
    int x;cin>>x;
    for(int i=-200;i<=200;i++){
    
    
        for(int j=-200;j<=200;j++){
    
    
            if(f(i)-f(j)==x){
    
    
                cout<<i<<' '<<j<<endl;
                return ;
            }
        }
    }
}
signed main(){
    
    
    solve();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44178736/article/details/115185427