The D problem was terrible. It was later than when I was solving it in December. I will review it firmly.
Since it is diagonal, the row and column numbers are the same.
answerA1.py
s=[input()[i] for i in range(3)]
print("".join(s))
Judge whether it is a palindrome in order from A to B. You just have to judge one character at a time.
answerB.py
a,b=map(int,input().split())
ans=0
for i in range(a,b+1):
s=str(i)
l=len(s)
for i in range(l//2):
if s[i]!=s[l-1-i]:
break
else:
ans+=1
print(ans)
** I misread the question sentence ** and thought that there were ** cards in all of the 9 squares **, but it was easy because I only had to ** exist **. It's spicy.
answerC.py
n,m=map(int,input().split())
if n==1 and m==1:
print(1)
elif n==1:
print(m-2)
elif m==1:
print(n-2)
else:
print((n-2)*(m-2))
The easiest way is to move both a and b, but it's O ($ n ^ 2
Consider the number of candidates for a above. First of all, for l above, it is sufficient to consider how many b are below n, so it can be calculated by n // b. Furthermore, the number of numbers between l * b + 1 and n that have a remainder of 0 to k-1 is the smaller of n divided by b and k-1 (where k = When it is 0, k-1 becomes negative, so it is assumed to be larger than 0). The answer can be obtained by subtracting the above candidates for a ** and thinking about this by moving b.
Through this problem
I learned that.
answerD.py
n,k=map(int,input().split())
ans=n*(n-k)
for i in range(k+1,n+1):
ans-=(k*(n//i))
ans-=max(0,min(k-1,n%i))
print(ans)
Recommended Posts