結果

問題 No.2176 LRM Question 1
ユーザー MasKoaTSMasKoaTS
提出日時 2022-11-30 16:13:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 3,016 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 89,600 KB
最終ジャッジ日時 2024-04-16 14:37:03
合計ジャッジ時間 5,489 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
85,760 KB
testcase_01 AC 144 ms
85,760 KB
testcase_02 AC 207 ms
89,600 KB
testcase_03 AC 143 ms
85,760 KB
testcase_04 AC 146 ms
86,016 KB
testcase_05 AC 171 ms
89,216 KB
testcase_06 AC 166 ms
89,344 KB
testcase_07 AC 164 ms
89,088 KB
testcase_08 AC 164 ms
89,472 KB
testcase_09 AC 167 ms
88,704 KB
testcase_10 AC 205 ms
89,344 KB
testcase_11 AC 145 ms
85,760 KB
testcase_12 AC 145 ms
86,016 KB
testcase_13 AC 145 ms
85,760 KB
testcase_14 AC 210 ms
89,088 KB
testcase_15 AC 206 ms
89,344 KB
testcase_16 AC 195 ms
89,088 KB
testcase_17 AC 164 ms
89,088 KB
testcase_18 AC 148 ms
85,760 KB
testcase_19 AC 142 ms
85,888 KB
testcase_20 AC 141 ms
86,016 KB
testcase_21 AC 187 ms
88,832 KB
testcase_22 AC 166 ms
89,088 KB
testcase_23 AC 184 ms
89,088 KB
testcase_24 AC 149 ms
85,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from __future__ import annotations
import itertools as iter
import collections as coll
import heapq as hq
import bisect as bis
from decimal import Decimal as dec
from functools import cmp_to_key
import math
import sys
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
sys.setrecursionlimit(10 ** 6)
inp = sys.stdin.readline
input = lambda : inp().rstrip()
getN = lambda : int(inp())
getNs = lambda : map(int, inp().split())
getList = lambda :list(map(int, inp().split()))
getStrs = lambda n : [input() for _ in [0] * n]
def yexit(): print("Yes"); exit(0)
def nexit(): print("No"); exit(0)
pi = 3.141592653589793
mod = 1000000007
MOD = 998244353
INF = 4611686018427387903
dx = [1, 0, -1, 0];	dy = [0, 1, 0, -1]
#di = coll.defaultdict(int)

class ModInt:
	mod = 998244353

	def __init__(self, x):
		self.x = x % ModInt.mod

	@classmethod
	def set_mod(cls, mod: int) -> None:
		ModInt.mod = mod
		
	def __str__(self):
		return str(self.x)

	__repr__ = __str__

	def __add__(self, other):
		return (ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other))

	def __sub__(self, other):
		return (ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other))

	def __mul__(self, other):
		return (ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other))

	def __truediv__(self, other):
		return (ModInt(self.x * pow(other.x, ModInt.mod - 2, ModInt.mod)) if isinstance(other, ModInt)
		  else ModInt(self.x * pow(other, ModInt.mod - 2, ModInt.mod)))

	def __pow__(self, other):
		return ModInt(pow(self.x, other.x, ModInt.mod)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, ModInt.mod))

	__radd__ = __add__

	def __rsub__(self, other):
		return (ModInt(other.x - self.x) if isinstance(other, ModInt) else ModInt(other - self.x))

	__rmul__ = __mul__

	def __rtruediv__(self, other):
		return (ModInt(other.x * pow(self.x, ModInt.mod - 2, ModInt.mod)) if isinstance(other, ModInt)
		  else ModInt(other * pow(self.x, ModInt.mod - 2, ModInt.mod)))

	def __rpow__(self, other):
		return ModInt(pow(other.x, self.x, ModInt.mod)) if isinstance(other, ModInt) else ModInt(pow(other, self.x, ModInt.mod))

	def __iadd__(self, other):
		self = self + other
		return self

	def __isub__(self, other):
		self = self - other
		return self

	def __imul__(self, other):
		self = self * other
		return self

	def __itruediv__(self, other):
		self = self / other
		return self
	
	@classmethod
	def nCk(n, k) -> ModInt:
		if(isinstance(n, ModInt)):
			n = n.x
		if(isinstance(k, ModInt)):
			k = k.x
		r = min(n - k, k)
		ret = ModInt(1)
		for i in range(n - r + 1, n + 1):
			ret *= i
		d = ModInt(1)
		for i in range(2, r + 1):
			d *= i
		ret /= d
		return ret


"""
Main Code
"""

L, R, M = getNs()

if(L >= M):
	print(0)
	exit(0)
elif(R >= M):
	R = M - 1

ModInt.set_mod(M)
def solve(n):
	a = ModInt(1)
	b = ModInt(1)
	ret = ModInt(0)
	for i in range(1, n + 1):
		a *= i
		b *= a
		ret += b
	return ret

print(solve(R) - solve(L - 1))
0