Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <set>
  6. #include <string>
  7. #include <map>
  8. #include <queue>
  9. #include <cmath>
  10. #include <algorithm>
  11. #pragma comment(linker, "/STACK:550000000")
  12.  
  13. using namespace std;
  14.  
  15. int get_ans(int n, int p) {
  16. if (n == 1)
  17. return 1;
  18. else return ((get_ans(n - 1, p) + p - 1) % n + 1);
  19. }
  20.  
  21.  
  22. int main() {
  23.  
  24. freopen("joseph.in", "r", stdin);
  25. freopen("joseph.out", "w", stdout);
  26.  
  27. int n, p;
  28. scanf("%d%d", &n, &p);
  29. int ans = get_ans(n, p);
  30. cout << ans;
  31. //system("pause");
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement