-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJosephus_Problem.cpp
More file actions
50 lines (44 loc) · 804 Bytes
/
Copy pathJosephus_Problem.cpp
File metadata and controls
50 lines (44 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <cstring>
#include <iomanip>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <vector>
#include <new>
#include <bitset>
#include <ctime>
#include <stdint.h>
#include <unistd.h>
using namespace std;
#define ll long long int
#define INF 2147483647
#define PI acos(-1.0)
#define EPS 1e-9
template <typename X> X gcd(X a, X b){if(!b)return a; else return gcd(b, a%b);}
typedef vector<int> vi;
typedef pair<int, int> ii;
int n, d, i, r;
int solve(){
i=1;
r=0;
while(i<=n)
r=(r+d)%i, ++i;
return r+1;
}
int main(){
while(1){
scanf("%d %d", &n, &d);
if(!n && !d)
break;
printf("%d %d %d\n", n, d, solve());
}
return 0;
}