n=int(input())a=[]for L in range(1,n+1): t=L-sum(a)%L while t in a:t+=L a+=[t]print(a[-1])
10000
16180
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!