結果
問題 | No.752 mod数列 |
ユーザー |
![]() |
提出日時 | 2018-11-09 22:21:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,376 ms / 2,000 ms |
コード長 | 1,341 bytes |
コンパイル時間 | 1,965 ms |
コンパイル使用メモリ | 200,632 KB |
最終ジャッジ日時 | 2025-01-06 16:07:14 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include<bits/stdc++.h>using namespace std;using Int = long long;template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}struct FastIO{FastIO(){cin.tie(0);ios::sync_with_stdio(0);}}fastio_beet;//INSERT ABOVE HEREsigned main(){Int p,q;cin>>p>>q;const Int MAX = 5e7;vector<Int> dp(MAX,0);for(Int i=1;i<MAX;i++) dp[i]=dp[i-1]+(p%i);map<Int, Int> dp2;dp2[MAX-1]=dp[MAX-1];auto calc=[&](Int x)->Int{if(x<MAX) return dp[x];/*if(dp2.count(x)) return dp2[x];Int &res=dp2[x];Int k=(--dp2.upper_bound(x))->second+1;res=dp2[k-1]+(x-k+1)*p;*/Int k=MAX,res=dp[k-1]+(x-k+1)*p;auto sub=[&](Int a,Int b){assert(p/a==p/b);res-=(p/a)*(a+b)*(b-a+1)/2;};while(k<x){if(p/k==p/x){sub(k,x);break;}Int l=k,r=x;while(l+1<r){Int m=(l+r)>>1;if(p/k==p/m) l=m;else r=m;}sub(k,l);k=r;}return res;};for(Int i=0;i<q;i++){Int l,r;cin>>l>>r;cout<<calc(r)-calc(l-1)<<"\n";}cout<<flush;return 0;}