I actually noticed this in the following AtCoder problem: https://atcoder.jp/contests/abc162/tasks/abc162_c I was turning a 200 * 200 * 200 for statement.
The output was done with the print function
to check the operation.
I am using the time
module for time measurement.
import time
import math
k=int(input())
stat = time.time()
k+=1
ans=0
for i in range(1,k):
for j in range(1,k):
for z in range(1,k):
print(i,j,k)
print(math.gcd(math.gcd(i,j),z))
ans+=math.gcd(math.gcd(i,j),z)
end = time.time()
print(ans)
print(end-stat)
##k=10 => 0.0718231201171875(s)
##k=100 => 20.816463232040405(s)
import math
import time
k=int(input())
start = time.time()
k+=1
ans=0
for i in range(1,k):
for j in range(1,k):
for z in range(1,k):
ans+=math.gcd(math.gcd(i,j),z)
end = time.time()
print(ans)
print(end-start)
#k=10 => 0.0009169578552246094(s)
#k=100 => 0.4900369644165039(s)
It seems that it takes a lot of time if print
also overlaps.
First try it while print
ing a little (k = 10 this time)
You must comment out when calculating time-consuming orders.
Recommended Posts