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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
typedef long long LL ;
// 欧拉筛
const int N = 1e6 + 10 ;
int primes [ N ] , cnt ; // primes[]存储所有素数
bool st [ N ] ; // st[x]存储x是否被筛掉
void get_primes ( int n ) {
memset ( st , 0 , sizeof st ) ;
cnt = 0 ;
for ( int i = 2 ; i < = n ; i + + ) {
if ( ! st [ i ] ) primes [ cnt + + ] = i ;
for ( int j = 0 ; primes [ j ] * i < = n ; j + + ) {
st [ primes [ j ] * i ] = true ;
if ( i % primes [ j ] = = 0 ) break ;
}
}
}
int main ( ) {
int n ;
cin > > n ;
get_primes ( n ) ;
for ( int i = 0 ; i < cnt ; i + + ) {
int p = primes [ i ] ;
int s = 0 ;
// 思路:由大到小+除法降维
// 优点: 不用考虑乘法而导致的爆int上限
for ( int j = n ; j ; j / = p ) s + = j / p ;
printf ( " %d %d \n " , p , s ) ;
}
return 0 ;
}