You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
720 B
32 lines
720 B
#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;
|
|
} |