返回题解分享
讨论 / 题解分享/ 帖子详情

质数判断 - 题解

/*
思路:
思路一:1. 判断是否是质数
*/

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

int function_find(int n) {
    if ( n == 1 ) {
        cout << 1 << endl;
        return 1;
    }
    for ( int i = 2; i <= sqrt(n)+1; i++ )//循环判断是否是质数 (1 >> 根号n)
        if ( n % i == 0 ) {
            cout << (n/i) << endl;
            return 1;
        }
    cout << "YES" << endl;
    return 1;
}

int main()
{
    int n;
    cin >> n;
    function_find(n);
    return 0;
}
0 回复 0 转发 0 喜欢 6 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!