結果
| 問題 | No.315 世界のなんとか3.5 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-08 23:54:25 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,555 bytes |
| 記録 | |
| コンパイル時間 | 308 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2024-09-14 20:28:02 |
| 合計ジャッジ時間 | 3,345 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 RE * 24 |
ソースコード
def solve(A, B, P):
return (f(B, P) - f(A, P) + is_valid(A, P)) % (10**9 + 7)
def is_valid(A, P):
if len(A) < 6:
a = int(A)
return (('3' in A) or (a % 3 == 0)) and (a % P != 0)
sumA = sum(map(int, A))
lowerA = int(A[-5:])
return (('3' in A) or (sumA % 3 == 0)) and (lowerA % P != 0)
def f(A, P):
if P == 8:
return f8(A)
elif P == 80:
return f80(A)
elif P == 800:
return f800(A)
def f80(A):
pass
def f800(A):
pass
def f8(A):
mod = 10**9 + 7
inv9 = 111111112
inv10 = 700000005
if len(A) < 5:
return f8_naive(int(A))
head = A[:-4]
tail = A[-4:]
n = len(head) - 1
pow10 = pow(10, n, mod)
pow9 = pow(9, n, mod)
cum0 = 0
cum1 = 0
has_no_3 = True
for a in head:
m = ord(a) - 48 # ord('0') = 48
cum0 = (cum0 + pow10 * m) % mod
pow10 = (pow10 * inv10) % mod
if has_no_3:
if m == 3:
has_no_3 = False
m -= m > 3
cum1 = (cum1 + pow9 * m) % mod
pow9 = (pow9 * inv9) % mod
if has_no_3:
return (8750 * cum0 - 3750 * cum1 + f8_naive(int(tail), cum0)) % mod
else:
return (8750 * cum0 - 3750 * cum1 + int(tail) - int(tail)//8) % mod
def f8_naive(n, cum=0):
cum %= 3
count = 0
for i in range(1, n + 1):
if i % 8 == 0:
continue
if ('3' in str(i)) or ((i + cum) % 3 == 0):
count += 1
return count
A, B, P = input().split()
print(solve(A, B, int(P)))