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.

23 lines
667 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
int a[10001] = {0}, n; //数组很大,记得开在外面哦
int main() {
ios::sync_with_stdio(false); //读入输出优化的强迫症
cin >> n;
//1就不用了从2到n一个一个来
for (int i = 2; i <= n; i++) {
//备份一下,不然等会被除掉了
int i2 = i;
//从2开始判断是否可以整除
for (int j = 2; j <= i; j++)
while (i2 % j == 0) {
a[j]++;
i2 /= j;
}
}
for (int i = 1; i <= 10000; i++) //输出
if (a[i] != 0) {
cout << i << " " << a[i] << endl;
}
}