Files
python/TangDou/LuoGuBook/P1403_Prepare.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

32 lines
720 B
C++

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
/**
* 功能:计算约数个数
* @param n
* @return
*/
LL getDivisorCount(LL x) {
unordered_map<int, int> primes; //key:质数 value:个数
//求质数因子
for (int i = 2; i <= x / i; i++)
while (x % i == 0) x /= i, primes[i]++; //primes[i]表示质数i因子的个数+1
//如果还有质数,那就加上
if (x > 1) primes[x]++;
//公式大法
LL res = 1;
for (auto p: primes) res = res * (p.second + 1);
return res;
}
LL res;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cout << i << " " << getDivisorCount(i) << endl;
return 0;
}