結果

問題 No.752 mod数列
ユーザー beetbeet
提出日時 2018-11-09 22:30:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 505 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 201,236 KB
実行使用メモリ 81,500 KB
最終ジャッジ日時 2023-08-13 11:50:49
合計ジャッジ時間 11,243 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
81,312 KB
testcase_01 AC 125 ms
81,292 KB
testcase_02 AC 125 ms
81,316 KB
testcase_03 AC 124 ms
81,372 KB
testcase_04 AC 126 ms
80,980 KB
testcase_05 AC 124 ms
81,020 KB
testcase_06 AC 125 ms
81,308 KB
testcase_07 AC 126 ms
81,500 KB
testcase_08 AC 124 ms
81,000 KB
testcase_09 AC 124 ms
81,044 KB
testcase_10 AC 128 ms
81,236 KB
testcase_11 AC 125 ms
81,368 KB
testcase_12 AC 128 ms
81,368 KB
testcase_13 AC 127 ms
81,312 KB
testcase_14 AC 128 ms
81,392 KB
testcase_15 AC 146 ms
80,976 KB
testcase_16 AC 150 ms
80,988 KB
testcase_17 AC 505 ms
81,000 KB
testcase_18 AC 153 ms
80,984 KB
testcase_19 AC 156 ms
81,004 KB
testcase_20 AC 167 ms
81,372 KB
testcase_21 AC 165 ms
80,984 KB
testcase_22 AC 166 ms
81,204 KB
testcase_23 AC 168 ms
80,988 KB
testcase_24 AC 168 ms
81,312 KB
testcase_25 AC 293 ms
81,312 KB
testcase_26 AC 402 ms
81,352 KB
testcase_27 AC 266 ms
81,240 KB
testcase_28 AC 361 ms
80,976 KB
testcase_29 AC 253 ms
81,308 KB
testcase_30 AC 423 ms
81,292 KB
testcase_31 AC 125 ms
81,368 KB
testcase_32 AC 124 ms
81,180 KB
testcase_33 AC 125 ms
80,980 KB
権限があれば一括ダウンロードができます

ソースコード

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


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int p,q;
  cin>>p>>q;
  
  const Int MAX = 1e7;
  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);
          res-=(p/a)*(a+b)*(b-a+1)/2;          
        };
      
      while(k<x){
        if(p/k==p/x){
          sub(k,x);
          break;
        }
        Int l=k+(p%k)/(p/k);
        sub(k,l);
        k=l+1;
      }
      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;
}
0