fork(1) download
  1. import sys
  2.  
  3. def lucky( n, k ):
  4. if n ==1:
  5. return 1
  6. else:
  7. return ((lucky (n-1, k) + k-1) % n)+1
  8.  
  9. cases= int(sys.stdin.readline())
  10. current= 0
  11. while current < cases:
  12. current += 1
  13. n = int(sys.stdin.readline())
  14. print lucky (n, 2)
Runtime error #stdin #stdout 0.03s 8296KB
stdin
4
5
11
45
23987443
stdout
3
7
27