其他分享
首页 > 其他分享> > acwing- 质因数分解

acwing- 质因数分解

作者:互联网

链接:https://www.acwing.com/problem/content/description/451/

来源:acwing

思路:

简单质因分解,题目说明了一定是两个不同的质数,那只要求其中一个的,就得出另一个了

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n ;
    for(int i = 2 ; i <= n ; i++){
        if(n%i==0){
            bool ok =true;
            for(int j = 2 ; j * j< i ; j++){//判断质数
                if(i%j==0) ok = false;
            }
            if(ok) {
                cout << n/i << endl;
                break;
            }
        }
    }
    return 0;
}

标签:www,ok,因数分解,int,质数,acwing
来源: https://blog.csdn.net/kuangzeng/article/details/117373968