hiho week 94 register

Ended

Participants:787

Verdict:Accepted
Score:100 / 100
Submitted:2016-04-17 15:57:22

Lang:G++

Edit
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
#include "stdio.h"
int y,t,o;
int a(int x)
{
    if(x==1)
        return 0;
    if(x<=y)
        return (a(x-1)+y)%x;
    t=a(x-x/y);
    o=x%y;
    if(t<o)
        return t-o+x;
    else
        return t-o+(t-o)/(y-1);
    return 0;
}
int main()
{
    int b,c;
    scanf("%d",&b);
    while(b--)
    {
        scanf("%d %d",&c,&y);
        printf("%d\n",a(c));
    }
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX