結果

問題 No.1966 Median of Divisors
ユーザー chineristACchineristAC
提出日時 2022-06-03 21:31:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 76,944 KB
最終ジャッジ日時 2023-10-21 01:38:56
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
56,060 KB
testcase_01 AC 47 ms
56,060 KB
testcase_02 AC 54 ms
60,156 KB
testcase_03 AC 59 ms
65,704 KB
testcase_04 AC 200 ms
76,896 KB
testcase_05 AC 262 ms
76,944 KB
testcase_06 AC 244 ms
76,876 KB
testcase_07 AC 89 ms
76,824 KB
testcase_08 AC 163 ms
76,848 KB
testcase_09 AC 190 ms
76,924 KB
testcase_10 AC 193 ms
76,892 KB
testcase_11 AC 141 ms
76,848 KB
testcase_12 AC 163 ms
76,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N
        self.group = N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        stack = [x]
        while self._parent[stack[-1]]!=stack[-1]:
            stack.append(self._parent[stack[-1]])
        for v in stack:
            self._parent[v] = stack[-1]
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        self.group -= 1

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
            return gy
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]
            return gx

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

mod = 10**9 + 7

i2 = pow(2,mod-2,mod)
i6 = pow(6,mod-2,mod)

for _ in range(int(input())):
    N,M = mi()

    S = pow(N,M,mod)
    all = (S*(S+1) % mod) * i2 % mod
    T = pow(N,M//2,mod)
    sq = (T*(2*T+1) % mod)*((T+1)*i6 % mod) % mod

    print((all-sq)%mod)
0