Break through in one and a half minutes. Just write.
S = input()
if S[-1] != 's':
print(S + 's')
else:
print(S + 'es')
Break through in one and a half minutes. Just write. Why is the problem name "going to prison"?
N = int(input())
t = 0
max_run_length = 0
for _ in range(N):
D1, D2 = map(int, input().split())
if D1 == D2:
t += 1
else:
t = 0
max_run_length = max(max_run_length, t)
if max_run_length >= 3:
print('Yes')
else:
print('No')
Break through in 4 minutes. Just write. I thought that the amount of calculation would be okay for a few seconds, but I thought it was a C problem and it would be okay, so I submitted it with PyPy and AC.
N = int(input())
result = 0
for A in range(1, N + 1):
for B in range(1, (N // A) + 1):
C = N - A * B
if C == 0:
continue
result += 1
print(result)
Since A × B + 1 ≤ N is sufficient, the formula is transformed into B ≤ (N-1) ÷ A, and the range of B can be obtained in one shot.
N = int(input())
result = 0
for A in range(1, N + 1):
result += (N - 1) // A
print(result)
I couldn't break through. I thought about 50 minutes, but I couldn't implement it in 5 minutes.
It broke through in 36 minutes and a half. I solved some loop detection problems, so I didn't think it was that difficult. It's unconvincing if I / O example 3 doesn't fit well and it takes so long (laughs). ).
N, X, M = map(int, input().split())
existence = [False] * M
a = []
A = X
for i in range(N):
if existence[A]:
break
existence[A] = True
a.append(A)
A = A * A % M
try:
loop_start = a.index(A)
except:
loop_start = len(a)
result = sum(a[:loop_start])
N -= loop_start
if N != 0:
a = a[loop_start:]
loops = N // len(a)
remainder = N % len(a)
result += sum(a) * loops + sum(a[:remainder])
print(result)
Recommended Posts