Problem «Square»
Let the pencil move by the line and put crosses through every (n + 1) point. Lets associate every point on the line with point on square perimeter. Namely, point x on the line will be associated with point on square perimeter that we will reach if we move pencil around square to x clockwise. Then lower left corner will be associated with all points 4np for every non-negative integer p. Crosses will be associated with points k(n + 1) for some non-negative k. Nearest point of overlap of two families of points will be in point LCM(n + 1, 4n). Then we will put crosses.
AC code:
#includeusing namespace std;int main(){ int T; long long n; cin>>T; while(T--) { cin>>n; long long a=4*n,b=n+1,r=a%b; while(r) { a=b; b=r; r=a%b; } long long cross=4*n/b+1; cout< <