problem
stringclasses
67 values
user
stringlengths
13
13
submission_order
int64
1
57
result
stringclasses
10 values
execution_time
stringlengths
0
8
memory
stringclasses
88 values
code
stringlengths
47
7.62k
QPC004_C1
AD83A66F52985
2
RE
1904 ms
158 MiB
'''python def solve(a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: n = int(input()) act = a result.append(act) for i in range(1, n): act = pow(act, 2, L) result.append(a) return result '''
QPC004_C1
AD83A66F52985
3
WA
2235 ms
160 MiB
'''python def solve(n:int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: act = a result.append(act) for i in range(1, n): act = pow(act, 2, L) result.append(a) return result '''
QPC004_C1
AD83A66F52985
4
WA
1810 ms
158 MiB
'''python def solve(n:int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: act = a result.append(act) for i in range(1, n-1): act = pow(a, 2, L) result.append(a) return result '''
QPC004_C1
AD83A66F52985
5
WA
1647 ms
158 MiB
'''python def solve(n:int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: act = a result.append(act) for i in range(1, n-1): act = pow(act, 2, L) result.append(a) return result '''
QPC004_C1
AD83A66F52985
6
WA
1703 ms
158 MiB
'''python def solve(n:int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: act = a result.append(act) for i in range(1, n-1): act = act**2 % L result.append(a) return result '''
QPC004_C1
AD83A66F52985
7
WA
1766 ms
164 MiB
'''python def solve(n:int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: act = a result.append(act) for i in range(1, n-1): act = act**2 % L result.append(act) return result '''
QPC004_C1
AD83A66F52985
8
RE
1582 ms
157 MiB
'''python def solve(n:int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: act = a result.append(act) for i in range(0, n-1): act = act**2 % L result.append(ac) return result '''
QPC004_C1
AD83A66F52985
9
AC
2951 ms
192 MiB
'''python def solve(n:int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: act = a result.append(act) for i in range(n-1): act = act**2 % L result.append(act) return result '''
QPC004_C1
ADEC3ACD2C70C
1
AC
2895 ms
191 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: result.append(a) for i in range(1,n): result.append(result[-1]**2%L) return result '''
QPC004_C1
AE07079D9535D
1
RE
1671 ms
158 MiB
'''python def solve(a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: result.append(a % L) for i in range(100000): last = result[-1] result.append(last*last % L) return result '''
QPC004_C1
AE07079D9535D
2
RE
2009 ms
158 MiB
'''python def solve(a, L): result = [] result.append(a % L) for i in range(100000): last = result[-1] result.append(last*last % L) return result solve(10, 13) '''
QPC004_C1
AE07079D9535D
3
WA
1775 ms
164 MiB
'''python def solve(n, a, L): result = [] result.append(a % L) for i in range(n): last = result[-1] result.append(last*last % L) return result '''
QPC004_C1
AE07079D9535D
4
AC
2883 ms
193 MiB
'''python def solve(n, a, L): result = [] result.append(a % L) for i in range(n-1): last = result[-1] result.append(last*last % L) return result '''
QPC004_C1
AE081D378696E
1
TLE
3000 ms
159 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: for i in range(n): result.append(a**(2**(i))%L) return result '''
QPC004_C1
AE081D378696E
2
AC
2675 ms
193 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: result.append(a % L) for i in range(1, n): result.append(result[-1]**2 % L) return result '''
QPC004_C1
AE12CC5569977
1
WA
1888 ms
158 MiB
'''python def solve(a: int, L: int, n: int) -> list[int]: result: list[int] = [] result.append(a) for i in range(1, n): result.append(pow(result[i - 1], 2, L)) return result '''
QPC004_C1
AE453A9CBA36B
1
RE
'''python def solve(a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: for i in range(n): result.append(a): a = (a*a)%L; return result '''
QPC004_C1
AE453A9CBA36B
2
RE
1969 ms
157 MiB
'''python def solve(a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: for i in range(n): result.append(a) a = (a*a)%L return result '''
QPC004_C1
AE453A9CBA36B
3
AC
2878 ms
192 MiB
'''python def solve(n:int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: for i in range(n): result.append(a) a = (a*a)%L return result '''
QPC004_C1
AE8FC8BF70196
1
TLE
3000 ms
160 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: for i in range(n): result.append(a**(2**i) % L) return result '''
QPC004_C1
AE8FC8BF70196
2
TLE
3000 ms
160 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [a**(2**i) % L for i in range(n)] return result '''
QPC004_C1
AEBE90D991F1A
1
TLE
3000 ms
145 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: result.append(a) if n == 1: return result for i in range(n-1): result.append(result[-1] * a**(2**i)) return result '''
QPC004_C1
AEBE90D991F1A
2
TLE
3000 ms
143 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: result.append(a) for i in range(n-1): result.append(result[-1] * a**(2**i) % L) return result '''
QPC004_C1
AEBE90D991F1A
3
AC
2380 ms
175 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: result.append(a) for i in range(n-1): result.append(result[-1] ** 2 % L) return result '''
QPC004_C1
AEFCF629DBBD5
1
WA
1899 ms
143 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: return result '''
QPC004_C1
AEFCF629DBBD5
2
WA
1744 ms
143 MiB
'''python def solve(n: int, a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: return result '''
QPC004_C1
AF9FD71BF7073
1
RE
1738 ms
157 MiB
'''python def solve(a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: for k in range(n): result.append(a**(2**k) % L) return result '''
QPC004_C1
AF9FD71BF7073
2
WA
1763 ms
158 MiB
'''python def solve(a: int, L: int, n:int) -> list[int]: result: list[int] = [] # Write your code here: for k in range(n): result.append(a**(2**k) % L) return result '''
QPC004_C1
AF9FD71BF7073
3
WA
1790 ms
160 MiB
'''python def solve(a: int, L: int, n:int) -> list[int]: result: list[int] = [] # Write your code here: n = 10 for k in range(n): result.append(a**(2**k) % L) return result '''
QPC004_C1
AF9FD71BF7073
4
RE
1470 ms
157 MiB
'''python def solve(a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: n = 1 for k in range(n): result.append(a**(2**k) % L) return result '''
QPC004_C1
AF9FD71BF7073
5
WA
1672 ms
158 MiB
'''python def solve(a: int, L: int, n:int) -> list[int]: result: list[int] = [] # Write your code here: k = 0 while True: if a >= L: a %= L result.append(a) a **= 2 k += 1 if k == n: break return result '''
QPC004_C1
AF9FD71BF7073
6
RE
1605 ms
158 MiB
'''python def solve(a: int, L: int) -> list[int]: result: list[int] = [] # Write your code here: k = 0 while True: if a >= L: a %= L result.append(a) a **= 2 k += 1 if k == n: break return result '''
QPC004_C2
A0A8908519E40
1
TLE
3000 ms
157 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: test = 1 while test % a != 0: test += L result = test // a return result '''
QPC004_C2
A0A8908519E40
2
WA
1627 ms
158 MiB
'''python def expansion_euclid(a: int, b: int) -> [int,int,int]: if b == 0: return a,1,0 gcd,x1,y1 = expansion_euclid(b, a % b) x = x1 y = x1 - (a // b) * y1 return gcd,x,y def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: _,X,_ = expansion_euclid(a,L) return X % L '''
QPC004_C2
A0A8908519E40
3
AC
1847 ms
158 MiB
'''python def expansion_euclid(a: int, b: int) -> [int,int,int]: if b == 0: return a, 1, 0 gcd, x1, y1 = expansion_euclid(b, a % b) x = y1 y = x1 - (a // b) * y1 return gcd, x, y def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: _, X, _ = expansion_euclid(a, L) return X % L '''
QPC004_C2
A1181B21C7581
1
AC
1912 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # 拡張ユークリッドの互除法 def extended_gcd(x, y): if y == 0: return 1, 0 s, t = extended_gcd(y, x % y) return t, s - (x // y) * t x, _ = extended_gcd(a, L) result = x % L return result '''
QPC004_C2
A1CC146361C53
1
AC
1826 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = pow(a, -1, L) return result '''
QPC004_C2
A29F1C1D13735
1
AC
1843 ms
158 MiB
'''python def extgcd(a, b): if b: d, y, x = extgcd(b, a % b) y -= (a // b) * x return d, x, y return a, 1, 0 def solve(a: int, L: int) -> int: _, x, _ = extgcd(a, L) return x % L '''
QPC004_C2
A2D404E7FC939
1
AC
1723 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result=pow(a,-1,L) return result '''
QPC004_C2
A367F108D3107
1
RE
1972 ms
158 MiB
'''python x, y = 0, 1 def gcdExtended(a, b): global x, y if (a == 0): x = 0 y = 1 return b gcd = gcdExtended(b % a, a) x1 = x y1 = y x = y1 - (b // a) * x1 y = x1 return gcd def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: g = gcdExtended(A, M) if (g != 1): print("Inverse doesn't exist") else: res = (x % M + M) % M g = gcdExtended(A, M) result = (x % M + M) % M return result '''
QPC004_C2
A367F108D3107
2
RE
1677 ms
158 MiB
'''python x, y = 0, 1 def gcdExtended(a, b): global x, y if (a == 0): x = 0 y = 1 return b gcd = gcdExtended(b % a, a) x1 = x y1 = y x = y1 - (b // a) * x1 y = x1 return gcd def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: g = gcdExtended(A, M) if (g != 1): print("Inverse doesn't exist") else: res = (x % M + M) % M g = gcdExtended(A, M) result = (x % M + M) % M return result '''
QPC004_C2
A367F108D3107
3
AC
1708 ms
158 MiB
'''python x, y = 0, 1 def gcdExtended(a, b): global x, y if a == 0: x = 0 y = 1 return b gcd = gcdExtended(b % a, a) x1 = x y1 = y x = y1 - (b // a) * x1 y = x1 return gcd def solve(a: int, L: int) -> int: global x, y g = gcdExtended(a, L) if g != 1: return -1 result = (x % L + L) % L return result '''
QPC004_C2
A42D554836CE1
1
AC
1847 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: _,X,_ = extended_euclid(a,L) return X % L def extended_euclid(a: int, b: int) -> tuple[int,int,int]: if b == 0: return a,1,0 gcd,x1,y1 = extended_euclid(b,a%b) x = y1 y = x1 - (a // b) * y1 return gcd,x,y '''
QPC004_C2
A4C1DED22C7E0
1
AC
1632 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = pow(a, -1, L) return result '''
QPC004_C2
A592E09ABA386
1
AC
1752 ms
158 MiB
'''python def extended_gcd(a, b): if a == 0: return b, 0, 1 else: g, x, y = extended_gcd(b % a, a) return g, y - (b // a) * x, x def solve(a: int, L: int) -> int: g, x, y = extended_gcd(a, L) if g != 1: return None # Modular inverse doesn't exist if a and L are not coprime else: return x % L # Example usage: a = 3 L = 11 print(solve(a, L)) # Output should be 4, since 3 * 4 mod 11 = 1 '''
QPC004_C2
A5BFDB3B79AC7
1
TLE
3000 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: p = 0 while True: if (p*L + 1) % a == 0: result = (p*L + 1) // a break p += 1 return result '''
QPC004_C2
A616000848340
1
AC
2102 ms
158 MiB
'''python def solve(a: int, L: int) -> int: return pow(a, -1, L) '''
QPC004_C2
A64CFBF41851C
1
RE
1902 ms
156 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = pow(a,calculate_totient(N)-1,L) return result def find_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: # 同じ約数を二重に追加しない divisors.append(n // i) return sorted(divisors) def calculate_totient(N): if N == 1: print(1) else: N_factor = find_divisors(N)[1:] totient = N while N_factor: totient = (totient*(N_factor[0]-1))//N_factor[0] N_factor = [k for k in N_factor if k % N_factor[0] != 0] return totient '''
QPC004_C2
A64CFBF41851C
2
TLE
3000 ms
156 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = pow(a,calculate_totient(L)-1,L) return result def find_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: # 同じ約数を二重に追加しない divisors.append(n // i) return sorted(divisors) def calculate_totient(N): if N == 1: print(1) else: N_factor = find_divisors(N)[1:] totient = N while N_factor: totient = (totient*(N_factor[0]-1))//N_factor[0] N_factor = [k for k in N_factor if k % N_factor[0] != 0] return totient '''
QPC004_C2
A64CFBF41851C
3
TLE
3000 ms
156 MiB
'''python def solve(a: int, L: int) -> int: return pow(a, calculate_totient(L) - 1, L) def calculate_totient(n: int) -> int: result = n p = 2 while p * p <= n: if n % p == 0: while n % p == 0: n //= p result -= result // p # φ(n) *= (1 - 1/p) p += 1 if n > 1: result -= result // n return result '''
QPC004_C2
A64CFBF41851C
4
RE
2081 ms
157 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = pow(a,calculate_totient(L)-1,L) return result def find_prime_factors(n): factors = [] is_prime = [True] * (int(n**0.5) + 1) is_prime[0:2] = [False,False] for i in range(int(n**0.5) + 1): if is_prime[i]: for j in range(2*i,int(n**0.5) + 1,i): is_prime[j] = False if n % i == 0: factors.append(i) while n % i == 0: n //= i if n > 1: factors.append(n) return factors def calculate_totient(N): if N == 1: print(1) else: prime_factors = find_prime_factors(N) totient = N for p in prime_factors: totient -= totient//p return totient '''
QPC004_C2
A64CFBF41851C
5
AC
2398 ms
156 MiB
'''python def extended_euclidean(a: int, b: int) -> tuple[int, int, int]: # when b == 0: if b == 0: return a, 1, 0 # recursive step gcd, x1, y1 = extended_euclidean(b, a % b) # update x and y x = y1 y = x1 - (a // b) * y1 return gcd, x, y def solve(a: int, L: int) -> int: _, x, _ = extended_euclidean(a, L) return x % L '''
QPC004_C2
A6C475D5681BA
1
AC
1785 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: def egcd(a: int, b: int): if b == 0: return (a, 1, 0) g, x, y = egcd(b, a % b) return (g, y, x - (a // b) * y) # a と L は互いに素なので gcd(a, L) = 1 g, x, _ = egcd(a, L) # xが a の逆元 (mod L) であるが、負の場合もあるので正の値に変換 result = x % L return result '''
QPC004_C2
A6FBDD6160002
1
RE
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: def extgcd(a,b): d = a if b != 0: d,(y,x) = extgcd(b,a % b) y -= (a//b) * x else: x = 1 y = 0 return d,(x,y) _,(v,_) = extgcd(a,L) v = (v + L) % L result = v return result '''
QPC004_C2
A6FBDD6160002
2
RE
1742 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: def extgcd(a,b): d = a if b != 0: d,(y,x) = extgcd(b,a % b) y -= (a//b) * x else: x = 1 y = 0 return d,(x,y) _,(v,_) = extgcd(a,L) v = (v + L) % L result = v '''
QPC004_C2
A6FBDD6160002
3
UME
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: import sys sys.setrecursionlimit(10000) def extgcd(a,b): d = a if b != 0: d,(y,x) = extgcd(b,a % b) y -= (a//b) * x else: x = 1 y = 0 return d,(x,y) _,(v,_) = extgcd(a,L) v = (v + L) % L result = v return result '''
QPC004_C2
A6FBDD6160002
4
AC
1789 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: # copied from https://qiita.com/akebono-san/items/f00c0db99342a8d68e5d :pray: a,b = a,L x, y, u, v = 1, 0, 0, 1 while b: k = a // b x -= k * u y -= k * v x, u = u, x y, v = v, y a, b = b, a % b x = (x + L) % L result = x return result '''
QPC004_C2
A6FEC4807363A
1
WA
1681 ms
157 MiB
'''python def solve(a: int, L: int) -> int: # Write your code here: for i in range(L - 1): if (a ** i) % L == 1: return i - 1 '''
QPC004_C2
A6FEC4807363A
2
TLE
3000 ms
158 MiB
'''python def solve(a: int, L: int) -> int: # Write your code here: for i in range(1, L): if (a ** i) % L == 1: return a ** (i - 1) % L '''
QPC004_C2
A6FEC4807363A
3
RE
1568 ms
157 MiB
'''python def extended_gcd(a, b): if b == 0: return a, 1, 0 gcd, x1, y1 = extended_gcd(b, a % b) x = y1 y = x1 - (a // b) * y1 return gcd, x, y def mod_inverse(a, L): gcd, x, _ = extended_gcd(a, L) if gcd != 1: raise ValueError() return x % L '''
QPC004_C2
A6FEC4807363A
4
AC
1821 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: return pow(a, -1, L) '''
QPC004_C2
A7054D908A792
1
RE
1795 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: m0, m1 = L, a y0, y1 = 0, 1 while m1: m0, m1 = m1, m0 % m1 y0, y1 = y1, y0 - y1 * (m0 // m1) if y0 < 0: y0 += L // m0 result = y0 return result '''
QPC004_C2
A7054D908A792
2
AC
1761 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: def extended_gcd(x, y): if y == 0: return x, 1, 0 gcd, x1, y1 = extended_gcd(y, x % y) return gcd, y1, x1 - (x // y) * y1 # a と L の最大公約数が 1 であれば逆元が存在 gcd, x, y = extended_gcd(a, L) result = x % L return result '''
QPC004_C2
A7A5A066F8CAE
1
WA
1901 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = pow(a -1, L) return result '''
QPC004_C2
A7A5A066F8CAE
2
UME
'''python from math import * def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = math.pow(a -1, L) return result '''
QPC004_C2
A7A5A066F8CAE
3
RE
1786 ms
157 MiB
'''python def extgcd(x, y): if y == 0: return (1, 0, x) else: s1, t1, g = extgcd(y, x % y) s = t1 t = s1 - (x // y) * t1 return (s, t, g) def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = s%L s, t, g = extgcd(a, L) return result '''
QPC004_C2
A7A5A066F8CAE
4
AC
2108 ms
158 MiB
'''python def extgcd(x, y): if y == 0: return (1, 0, x) else: s1, t1, g = extgcd(y, x % y) s = t1 t = s1 - (x // y) * t1 return (s, t, g) def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: s, t, g = extgcd(a, L) result = s%L return result '''
QPC004_C2
A8C7CD27DBF7A
1
TLE
3000 ms
158 MiB
'''python def gcd(a, b): if b == 0: return a return gcd(b, a % b) def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: if gcd(a, L) > 1: # modulo inverse does not exist return -1 for X in range(1, L): if (((a % L) * (X % L)) % L == 1): return X return -1 # return result '''
QPC004_C2
A8C7CD27DBF7A
2
AC
1597 ms
158 MiB
'''python x, y = 0, 1 def gcdExtended(a, b): global x, y # Base Case if (a == 0): x = 0 y = 1 return b # To store results of recursive call gcd = gcdExtended(b % a, a) x1 = x y1 = y # Update x and y using results of recursive # call x = y1 - (b // a) * x1 y = x1 return gcd def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: g = gcdExtended(a, L) if (g != 1): result = -1 else: result = (x % L + L) % L return result '''
QPC004_C2
A9190E613FF8E
1
AC
1972 ms
158 MiB
'''python def solve(a: int, L: int) -> int: return pow(a, -1, L) '''
QPC004_C2
A94E938F47B9A
1
TLE
3000 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: for b in range(L): if a*b % L == 1: return b #return result '''
QPC004_C2
A94E938F47B9A
2
TLE
3000 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: for b in range(L): if a*b % L == 1: return b return result '''
QPC004_C2
A94E938F47B9A
3
AC
1902 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: return pow(a, -1, L) #return result '''
QPC004_C2
A9C4FD3C72271
1
WA
1632 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 if L == 1: result = 0 else: result = 1 return result '''
QPC004_C2
A9C4FD3C72271
2
AC
2424 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 i0, i = a, L j0, j = 1, 0 while i != 0: q = i0 // i i0, i = i, i0 - q * i j0, j = j, j0 - q * j result = j0 % L return result '''
QPC004_C2
A9C85310D45C9
1
WA
1591 ms
158 MiB
'''python def solve(a: int, L: int) -> list[int]: result: int = 0 # Write your code here: result = 1 l = L-2 while(l > 0): if(l%2 == 1): result = (result*a)%L a = (a*a)%L l = int(l/2) return result '''
QPC004_C2
AA456D687BBD6
1
TLE
3000 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: for i in range(1, L): if (((a % L) * (a % L)) % L == 1): return i return result '''
QPC004_C2
AA456D687BBD6
2
RE
1716 ms
158 MiB
'''python def extended_gcd(a, b): if a == 0: return (b, 0, 1) else: g, x, y = extended_gcd(b % a, a) return (g, y - (b // a) * x, x) def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: g, x, y = extended_gcd(a, L) return x % m '''
QPC004_C2
AA456D687BBD6
3
AC
1789 ms
158 MiB
'''python def extended_gcd(a, b): if a == 0: return (b, 0, 1) else: g, x, y = extended_gcd(b % a, a) return (g, y - (b // a) * x, x) def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: g, x, y = extended_gcd(a, L) return x % L '''
QPC004_C2
AAB8ECE506040
1
AC
1788 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: return pow(a, -1, L) '''
QPC004_C2
ABDB2A97AF84F
1
RE
1780 ms
158 MiB
'''python from math import pow def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result =pow(a,-1,L) return result '''
QPC004_C2
ABDB2A97AF84F
2
AC
1698 ms
158 MiB
'''python def extGCD(a, b) : if b == 0 : return a, 1, 0 d, y, x = extGCD(b, a%b) y -= a//b * x return d, x, y def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: d,x,y=extGCD(a,L) result =x if result<0: result+=L return result '''
QPC004_C2
ABDEEDD3E1B41
1
AC
1995 ms
156 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 def extended_gcd(a: int, b: int): if a == 0: return b, 0, 1 gcd, x1, y1 = extended_gcd(b % a, a) x = y1 - (b // a) * x1 y = x1 return gcd, x, y gcd, x, y = extended_gcd(a, L) # Since a and L are coprime, gcd should be 1 if gcd != 1: raise ValueError("a and L are not coprime") # x is the modular inverse, we need to ensure it's positive result = x % L return result '''
QPC004_C2
ABF5573C7413F
1
AC
1825 ms
158 MiB
'''python # gcd(a, b)とax+by=gcd(a,b)を満たすx,yを返す def euclidean(a, b): x = w = 1 y = z = 0 while b: q = a // b r = a % b x, y, z, w = z, w, x - q * z, y - q * w a, b = b, r return a, x, y def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: _, x, _ = euclidean(a, L) result = x % L return result '''
QPC004_C2
ACDA3A7E160D0
1
RE
1694 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: for k in range(n): result = pow(a, 2**k, L) results.append(result) return result '''
QPC004_C2
ACDA3A7E160D0
2
RE
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: def extended_gcd(a,b): gcd, x1, y1 = extended_gcd(b % a,a) x = y1 - (b // a) * x1 y = x1 return gcd, x, y gcd, x, _ = extended_gcd(a,L) if gcd != 1: raise ValueError("互いに素で無いため逆元が存在しない。") else result = x % L return result '''
QPC004_C2
ACDA3A7E160D0
3
AC
1737 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: def extended_gcd(a,b): if a == 0: return b,0,1 gcd, x1, y1 = extended_gcd(b % a,a) x = y1 - (b // a) * x1 y = x1 return gcd, x, y gcd, x, _ = extended_gcd(a,L) if gcd != 1: raise ValueError("互いに素で無いため逆元が存在しない。") else: result = x % L return result '''
QPC004_C2
ACFCBD4C80E15
1
RE
1434 ms
140 MiB
'''python def solve(a: int, L: int) -> int: x = 0 L0 = L y = 0 while (a > 1): q = a // L t = m m = a % m a = t t = y y = x - q * y x = t if (x < 0): x = x + L0 return x '''
QPC004_C2
ACFCBD4C80E15
2
RE
1517 ms
140 MiB
'''python def solve(a: int, L: int) -> int: x = 0 L0 = L y = 0 while (a > 1): q = a // L t = m L = a % L a = t t = y y = x - q * y x = t if (x < 0): x = x + L0 return x '''
QPC004_C2
ACFCBD4C80E15
3
WA
1441 ms
140 MiB
'''python def solve(a: int, L: int) -> int: x = 0 L0 = L y = 0 while (a > 1): q = a // L t = L L = a % L a = t t = y y = x - q * y x = t if (x < 0): x = x + L0 return x '''
QPC004_C2
ACFCBD4C80E15
4
AC
1641 ms
141 MiB
'''python def solve(a: int, L: int) -> int: x = 1 L0 = L y = 0 while (a > 1): q = a // L t = L L = a % L a = t t = y y = x - q * y x = t if (x < 0): x = x + L0 return x '''
QPC004_C2
ADB4B0BC5FA96
1
WA
1471 ms
158 MiB
'''python def power(a,b,m): result = 1 while b > 0: if b % 2 != 0: result = (result * a) % m b //= 2 a = (a * a) % m return result def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = power(a, L-2, L) return result '''
QPC004_C2
ADB4B0BC5FA96
2
WA
1789 ms
158 MiB
'''python def power(a,b,m): result = 1 a %= m while b > 0: if b % 2 != 0: result = (result * a) % m b //= 2 a = (a * a) % m result %= m return result def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = power(a, L-2, L) return result '''
QPC004_C2
ADB4B0BC5FA96
3
AC
2328 ms
158 MiB
'''python def extended_euclidean(X,Y): if X<Y: b, a, GCD = extended_euclidean(Y,X) x = X y = Y a = d = 1 b = c = 0 while y>0: q = x//y r = x%y if r==0: break # GCD 구해짐 x,y,a,b,c,d = y,r,c,d,a-q*c,b-q*d return c,d,y def solve(a: int, L: int) -> int: result: int = 0 x,y,GCD = extended_euclidean(a, L) result = (x+L*1000)%L return result '''
QPC004_C2
ADD2B7DFE8ADC
1
AC
1986 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = pow(a, -1, L) return result '''
QPC004_C2
AEAE9A87FB663
1
AC
1712 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 result = pow(a, -1, L) return result '''
QPC004_C2
AF209BC1E092E
1
TLE
3000 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = 1 while True: if ((result * a) % L) == 1: break else: result = (result * a) % L return result '''
QPC004_C2
AF209BC1E092E
2
AC
1779 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: result = result = pow(a, -1, mod=L) return result '''
QPC004_C2
AF97A819D9535
1
AC
1811 ms
158 MiB
'''python def solve(a: int, L: int) -> int: result: int = 0 # Write your code here: def extended_gcd(x: int, y: int): if y == 0: return (1, 0, x) x2, y2, g = extended_gcd(y, x % y) return (y2, x2 - (x // y) * y2, g) x, _, g = extended_gcd(a, L) result = x % L return result '''
QPC004_C3
A12A28AA50C30
1
TLE
3000 ms
174 MiB
'''python from qiskit import QuantumCircuit, QuantumRegister from math import pi, acos, sqrt, asin from qiskit.circuit.library import XGate, ZGate, PhaseGate, CU1Gate """ You can apply oracle as follows: qc.compose(o, inplace=True) """ def QFT(n: int) -> QuantumCircuit: qc = QuantumCircuit(n) for i in range(n//2): qc.swap(i, n-i-1) for i in range(n): qc.h(i) for j in range(i+1, n): qc.append(CU1Gate(pi/2**(j-i)), [j, i]) return qc def B2(n: int, a: int) -> QuantumCircuit: qc = QuantumCircuit(n) qc.compose(QFT(n), range(n), inplace=True) for i in range(n): qc.append(PhaseGate(2*pi*a*(1/2)**(n-i)), [i]) qc.compose(QFT(n).inverse(), range(n), inplace=True) return qc def B3(n: int, a: int) -> QuantumCircuit: k, c = QuantumRegister(n), QuantumRegister(1) qc = QuantumCircuit(k, c) # qc.x(n) qc.append(QFT(n).control(1), [n, *range(n)]) for i in range(n): qc.append(PhaseGate(2*pi*a*(1/2)**(n-i)).control(1), [n, i]) qc.append(QFT(n).inverse().control(1), [n, *range(n)]) return qc.decompose(reps=2) def B4(n: int, s: int, t: int) -> QuantumCircuit: qc = QuantumCircuit(n + 1) # Write your code here: qc.compose(B3(n, -t), range(n + 1), inplace=True) qc.x(n) qc.compose(B3(n, -s), range(n + 1), inplace=True) qc.x(n) return qc def B5(n: int, a: int, L: int) -> QuantumCircuit: qc = QuantumCircuit(n + 1) a=L-a # Write your code here: qc.compose(B2(n+1, 2**n-a), range(n + 1), inplace=True) qc.compose(B4(n, 2**n-a, 2**n-a+L), range(n + 1), inplace=True) qc.x(n) qc.compose(B2(n+1, -2**n+L-a), range(n + 1), inplace=True) return qc def solve(n: int, a: int, L: int) -> QuantumCircuit: x, y = QuantumRegister(n), QuantumRegister(n + 1) qc = QuantumCircuit(x, y) # Write your code here: for i in range(n): qc.compose(B5(n, a, L).control(1), [i] + list(range(n, n + n + 1)), inplace=True) a += a a %= L return qc '''