Gửi bài giải
Điểm:
10,00
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
98M
Input:
stdin
Output:
stdout
Tác giả:
Người đăng:
Dạng bài
Bài tập lập trình sáng tạo
Bình luận
include <bits/stdc++.h>
long long findSecondLargestDivisor(long long x) { std::vector<long long> divisors; for (long long i = 1; i * i <= x; ++i) { if (x % i == 0) { divisors.pushback(i); if (i * i != x) { divisors.pushback(x / i); } } } std::sort(divisors.rbegin(), divisors.rend()); if (divisors.size() < 2) { return 1; // Trường hợp số nguyên tố hoặc chỉ có ước là 1 và chính nó } return divisors[1]; }
int main() { long long x; std::cin >> x; long long result = findSecondLargestDivisor(x); std::cout << result << std::endl; return 0; }