1 条题解
-
0
#include #include #include using namespace std;
const int MOD = 100000007;
long long max_power(int p, int n) { long long result = 1; long long current = p; while (current <= n) { result *= p; current *= p; } return result; }
int main() { int n; cin >> n;
if (n < 1) { cout << 0 << endl; return 0; } if (n == 1) { cout << 1 % MOD << endl; return 0; } vector<bool> is_prime(n + 1, true); is_prime[0] = is_prime[1] = false; vector<int> primes; if (n >= 2) { primes.push_back(2); } for (int i = 4; i <= n; i += 2) { is_prime[i] = false; } for (int i = 3; i <= n; i += 2) { if (is_prime[i]) { primes.push_back(i); if ((long long)i * i <= n) { for (int j = i * i; j <= n; j += 2 * i) { is_prime[j] = false; } } } } int sqrt_n = sqrt(n); long long ans = 1; for (int p : primes) { if (p <= sqrt_n) { long long power = max_power(p, n); ans = (ans * power) % MOD; } else { ans = (ans * p) % MOD; } } cout << ans % MOD << endl; return 0;}
- 1
信息
- ID
- 17224
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 8
- 标签
- 递交数
- 66
- 已通过
- 12
- 上传者