BASIC point :-
1%1 = 0
1% x = 1, for x > 1
x+1%x = 1, for all x.
for(i=(n-1);i>1;i--)
x=x%i;
when i=(n-1) ===> x will updated to 1 due to x%i returns 1
after that it never changed.
if i=1, then x will updated to 0 but when i=1, condition evaluates to false, So x can't updated one more time.