#include using namespace std;

int main() { int N; cin >> N;

int maxPrime = 2; // 初始化最大质因子为2

// 从2开始遍历到N的平方根
for (int i = 2; i * i <= N; i++) {
    // 如果i是N的因子,则更新最大质因子
    while (N % i == 0) {
        maxPrime = i;
        N /= i;
    }
}

// 如果N最后不等于1,则N本身就是最大质因子
if (N > 1) {
    maxPrime = N;
}

cout << maxPrime << endl;

return 0;

}


原文地址: https://www.cveoy.top/t/topic/pNyj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录