LibreOJ - 10202 樱花 数论,因子个数,唯一分解
int prime[maxn]; int vis[maxn]; int euler_sieve(int n) { int cnt = 0; vis[1] = 1; for (int i = 2; i <= n; i++) { if (!vis[i]) prime[cnt++] = i; for (int j = 0; j < cnt; j++) { if (i * prime[j] > n) break; vis[i * prime[j]] = 1; if (i % prime[j] == 0) break; } } return cnt; } int main() { int cnt = euler_sieve(1000002); unordered_map<int, ll> mp; int n = readint(); for (int i = 1; i <= n; i++){ if (!vis[i]) { mp[i]++; continue; } ll tmp = i; for (int j = 0; j < cnt && (ll)prime[j] * prime[j] <= tmp; j++) { if (tmp % prime[j] == 0) while (tmp % prime[j] == 0) mp[prime[j]]++, tmp /= prime[j]; } if (tmp > 1) mp[tmp]++; } ll res = 1ll; for (auto it = mp.begin(); it != mp.end(); it++) res = res * ((1ll + 2 * it->second) % MOD) % MOD; Put(res); }