結果

問題 No.752 mod数列
ユーザー beetbeet
提出日時 2018-11-09 22:10:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,032 bytes
コンパイル時間 3,309 ms
コンパイル使用メモリ 200,896 KB
実行使用メモリ 15,328 KB
最終ジャッジ日時 2023-08-13 11:34:49
合計ジャッジ時間 9,070 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
15,124 KB
testcase_01 AC 15 ms
10,736 KB
testcase_02 AC 15 ms
10,804 KB
testcase_03 AC 15 ms
10,652 KB
testcase_04 AC 15 ms
10,604 KB
testcase_05 AC 15 ms
10,812 KB
testcase_06 AC 15 ms
10,824 KB
testcase_07 AC 15 ms
10,728 KB
testcase_08 AC 15 ms
10,736 KB
testcase_09 AC 15 ms
10,708 KB
testcase_10 AC 468 ms
10,736 KB
testcase_11 AC 113 ms
10,616 KB
testcase_12 AC 322 ms
10,604 KB
testcase_13 AC 206 ms
10,740 KB
testcase_14 AC 483 ms
10,664 KB
testcase_15 AC 183 ms
10,604 KB
testcase_16 AC 199 ms
10,600 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;}

//INSERT ABOVE HERE
signed main(){
  Int p,q;
  cin>>p>>q;
  
  const Int MAX = 1e6;
  vector<Int> dp(MAX,0);
  for(Int i=1;i<MAX;i++) dp[i]=dp[i-1]+(p%i);  
  auto calc=
    [&](Int x)->Int{
      if(x<MAX) return dp[x];
      Int k=MAX,res=dp[k-1]+(x-k+1)*p;
      
      auto sub=
        [&](Int a,Int b){
          assert(p/a==p/b);
          Int c=p/a;
          res-=c*(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)<<endl;
  }
  return 0;
}
0