fork download
  1. local function Pow(v, p, m) --возведение в степень по модулю
  2. if p == 0 then return 1 end
  3. if p == 1 then return v end
  4.  
  5. if p % 2 == 1 then return (Pow(v, p - 1, m) * v) % m end
  6.  
  7. local x = Pow(v, p / 2, m)
  8. return (x * x) % m
  9. end
  10.  
  11. for i = 1, 30 do
  12. print(Pow(2, 1000000, 37))
  13. end
Success #stdin #stdout 0s 4504KB
stdin
Standard input is empty
stdout
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12