牛牛的“质因数” ###K //K
题目链接:https://ac.nowcoder.com/acm/contest/9982/I
思路: 埃氏筛的时候dp转移即可 即使会重复筛到,但最大的质因数会在最后更新保证正确性
因为是接在最后一位上面,假设当前的质因子是x位数 那么就记得把前面的数乘上10^x
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=4e6+10; 4 const int mod=1e9+7; 5 #define ll long long 6 #define pi pair<int,int> 7 #define fi first 8 #define sc second 9 #define pb push_back 10 ll dp[maxn]; 11 int st[maxn]; 12 13 14 int main() 15 { 16 ios::sync_with_stdio(0); 17 cin.tie(0); 18 int n; 19 cin>>n; 20 for(int i=2;i<=n;i++) 21 { 22 if(st[i]) continue; 23 dp[i]=i; 24 for(int j=i+i;j<=n;j+=i) 25 { 26 st[j]=1; 27 int k=i; 28 ll ten=1; 29 while(k) ten*=10,k/=10; 30 dp[j]=(dp[j/i]*ten%mod+i)%mod; 31 } 32 } 33 ll ans=0; 34 for(int i=2;i<=n;i++) 35 ans+=dp[i],ans%=mod; 36 cout<<ans<<'\n'; 37 38 39 40 }

浙公网安备 33010602011771号