-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLSLDR.c
50 lines (50 loc) · 716 Bytes
/
CLSLDR.c
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 <stdio.h>
int arr[1001][1001];
int ans(int n, int o)
{
if (n == 1)
{
arr[1][o] = 1;
return 1;
}
if (arr[n][o] != 0)
return arr[n][o];
int temp = ans(n - 1, o);
int start;
if (o % n == 0)
start = n;
else
start = o % n;
if (temp == 1)
{
arr[n][o] = start;
return arr[n][o];
}
int t2 = (start + temp) % n;
if (t2 == 0)
arr[n][o] = n;
else
{
arr[n][o] = t2;
}
return arr[n][o];
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, m, o;
scanf("%d %d %d", &n, &m, &o);
int temp = (m - 1 + ans(n, o)) % n;
if (temp == 0)
{
printf("%d\n", n);
}
else
{
printf("%d\n", temp);
}
}
}