Zoj4029 Now Loading!!!
题意:输入a,b数组,已知每一个z为$$\sum\limits_{1 \le i \le n}\Bigl\lfloor \frac{a_i}{\lceil\log_{p}a_i\rceil}\Bigr\rfloor$$,求$$(\sum\limits_{i=1}^{m} i \cdot z_i) \bmod 10^9$$
题解:可以发现分母很小,所以只要预处理枚举分母就可以
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define maxn 500100 typedef long long ll; using namespace std; ll a[maxn], b[maxn], T, n, m, cnt; int sum[maxn][35]; const ll mod = 1e9; int main(){ cin>>T; while(T--){ cnt = 0; cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) cin>>b[i]; sort(a+1, a+n+1); for(ll i=1;i<=n;i++) for(ll j=1;j<=32;j++) sum[i][j] = (sum[i-1][j]+a[i]/j)%mod; for(int i=1;i<=m;i++){ ll ans = 0, p = 1, num = 1; while(1){ int s = upper_bound(a+1, a+n+1, p)-a; if(s > n) break; int t = upper_bound(a+1, a+n+1, p*b[i])-a; if(s != t) ans = (ans+sum[t-1][num]-sum[s-1][num])%mod; num++; p *= b[i]; } cnt = (cnt+ans*i)%mod; } cout<<(cnt+mod)%mod<<endl; } return 0; }
posted on 2018-04-30 21:22 2855669158 阅读(387) 评论(0) 编辑 收藏 举报