Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <string>
- #include <map>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #pragma comment(linker, "/STACK:550000000")
- using namespace std;
- int get_ans(int n, int p) {
- if (n == 1)
- return 1;
- else return ((get_ans(n - 1, p) + p - 1) % n + 1);
- }
- int main() {
- freopen("joseph.in", "r", stdin);
- freopen("joseph.out", "w", stdout);
- int n, p;
- scanf("%d%d", &n, &p);
- int ans = get_ans(n, p);
- cout << ans;
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement