MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / J

Function J

code/mathematics/josephus.cpp:1–6  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1int J(int n, int k) {
2 if (n == 1) return 0;
3 if (k == 1) return n-1;
4 if (n < k) return (J(n-1,k)+k)%n;
5 int np = n - n/k;
6 return k*((J(np,k)+np-n%k%np)%np) / (k-1); }
7// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected