题目地址
只需求出
∑
k
=
1
m
N
/
p
k
\sum_{k=1}^m N/p^k
∑k=1mN/pk 且pk < N
代码:
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define int long long
#define sc scanf
#define pf printf
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+7;
const int N = 1000010;
int primes[N],c[N];
bool book[N];
signed main(){
IOS;
#ifdef ddgo
freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
#endif
int cnt = 0,n; cin>>n;
for(int i=2;i<=n;i++)
if(!book[i]){
primes[cnt++] = i;
for(int j=i;j*i<=n;j++) book[i*j] = true;
}
for(int i=0;i<cnt;i++){
int p = primes[i];
while(p <= n){
c[i] += n/p;
p *= primes[i];
}
}
for(int i=0;i<cnt;i++){
if(c[i]) cout<<primes[i]<<" "<<c[i]<<endl;
else break;
}
return 0;
}