P7892题解

· · 题解

题目意思:
是否有一个a,b,使得:

a*b=n 2*(a+b)+4<=m

对于30%的数据,我们可以使用m举ab
把m然后枚举ab
时间复杂度O(m),显然,对于1e8的数据,肯定会TLE
我们考虑用n来枚举ab
因为必须要a*b=n,所以可以枚举n的每一个分解
时间复杂度O(\sqrt{n})

AC Code

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t,n,m,i;
    cin>>t;
    while(t--){
        bool flag=false;
        cin>>n>>m;
        for(i=1;i*i<=n;i++){
            if(n%i==0){
                if((4+2*(i+n/i))<=m){
                    flag=true;
                    break;
                }
            }
        }
        if(flag) cout<<"Good"<<endl;
        else cout<<"Miss"<<endl;
    }
}