Created
September 28, 2017 06:22
-
-
Save mhmoodlan/11805a82fee784a2721ae9db3fba90e6 to your computer and use it in GitHub Desktop.
#DP #Adhoc #JousephProblem #UVa #Solved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=87 | |
#include <bits/stdc++.h> | |
#define ll long long | |
#define sz(v) ((int) ((v).size())) | |
#define clr(v, d) memset(v, d, sizeof(v)) | |
#define lp(i, n) for(int i = 0; i < (int)(n); ++i) | |
#define rep(i, v) for(int i = 0; i < sz(v); ++i) | |
using namespace std; | |
const int MAX = 15; | |
const int OO = 1e4; | |
int cache[105]; | |
int calcM(int n, int cycle) { | |
cache[0] = cache[1] = 0; | |
for(int i = 2; i <= n; i++) { | |
if(i == n) cache[i] = cache[i-1] + 1; | |
else | |
cache[i] = (cache[i-1] + cycle) % i; | |
} | |
return cache[n]; | |
} | |
int main() { | |
int n; | |
while(cin>>n && n!=0) { | |
lp(i, 100) { | |
clr(cache, -1); | |
calcM(n, i+1); | |
if(cache[n] == 12) { cout << i+1 << endl; break;} | |
//cout << cache[n-1] << endl; | |
} | |
} | |
//cout << calcM(7, 3) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment