【NOIP2012】【Luogu1075】质因数分解(模拟)

problem

  • 已知正整数 n 是两个不同的质数的乘积
  • 试求出两者中较大的那个质数

solution

  • 2个质数,所以没必要分解质因数。
  • 直接枚举,遇到小的一个因数,拿他除一下就是答案了。

codes

#include<iostream>
using namespace std;
int main(){
    int n;  cin>>n;
    for(int i = 2; i < n; i++){
        if(n%i == 0){
            cout<<n/i<<'\n';
            return 0;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_33957603/article/details/80951310
今日推荐