結果

問題 No.752 mod数列
ユーザー titia
提出日時 2025-03-27 01:54:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,013 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 82,576 KB
実行使用メモリ 85,140 KB
最終ジャッジ日時 2025-03-27 01:54:51
合計ジャッジ時間 10,921 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

P,Q=map(int,input().split())

S=[0]*(10**6)

for i in range(1,10**6):
    S[i]=P%i

for i in range(1,10**6):
    S[i]=S[i]+S[i-1]

LIST=[]
for i in range(1,10**6):
    LIST.append((P//i,i))

    if P//i<10**6:
        break

LIST.reverse()

LIST.append((10**9,0))

def calc(x):
    if x<10**6:
        return S[x]
    else:
        ANS=S[10**6-1]

        now=10**6

        for i in range(1,len(LIST)):
            MAX=min(x,LIST[i][0])

            # now~MAXの個数

            ko=MAX-now+1

            ANS+=P*ko-ko*(MAX+now)//2*LIST[i][1]           

            if x<=LIST[i][0]:
                return ANS
            else:
                now=LIST[i][0]+1
        re


for i in range(Q):
    x,y=map(int,input().split())

    minus=calc(x-1)
    plus=calc(y)

    print(plus-minus)

            
            
0