結果

問題 No.644 G L C C D M
ユーザー vwxyzvwxyz
提出日時 2021-08-11 18:57:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,494 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 81,940 KB
実行使用メモリ 89,576 KB
最終ジャッジ日時 2023-10-25 10:22:44
合計ジャッジ時間 5,713 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
88,788 KB
testcase_01 AC 142 ms
88,788 KB
testcase_02 AC 142 ms
88,796 KB
testcase_03 AC 144 ms
88,792 KB
testcase_04 AC 145 ms
88,792 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 145 ms
88,788 KB
testcase_10 AC 145 ms
89,292 KB
testcase_11 WA -
testcase_12 AC 145 ms
89,292 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 142 ms
89,292 KB
testcase_16 AC 143 ms
89,296 KB
testcase_17 AC 144 ms
89,288 KB
testcase_18 AC 147 ms
89,536 KB
testcase_19 AC 148 ms
89,196 KB
testcase_20 AC 146 ms
89,528 KB
testcase_21 AC 144 ms
89,288 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 144 ms
89,288 KB
testcase_26 AC 146 ms
89,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import functools
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines

def Divisors(N):
    divisors=[]
    for i in range(1,N+1):
        if i**2>=N:
            break
        elif N%i==0:
            divisors.append(i)
    if i**2==N:
        divisors+=[i]+[N//i for i in divisors[::-1]]
    else:
        divisors+=[N//i for i in divisors[::-1]]
    return divisors

N,M=map(int,readline().split())
divisors=Divisors(M)
primes=[]
mod=10**9+7
for d in divisors[1:]:
    for p in primes:
        if d%p==0:
            break
    else:
        primes.append(d)
l=len(primes)
ans=0
for bit in range(1<<l):
    cnt=0
    MM=M
    for i in range(l):
        if bit>>i&1:
            cnt+=1
            MM*=primes[i]
    if cnt%2==0:
        ans+=(N//MM)*(N//MM-1)
        ans%=mod
    else:
        ans-=(N//MM)*(N//MM-1)
        ans%=mod
for i in range(1,N-1):
    ans*=i
    ans%=mod
print(ans)
0