# PIP3 in PYTHON3 Install an error, you can&#8217;t find SSL

2023-03-16

1073 Joseph Ring benchmark time limit: 1 second space limit: 131072 kb score: 0Difficulty: Basic Questions Favorites Follow
N Personal sitting into a ring (number 1 -n), from the first person to count, the number of people who count them to K, the people behind them will be reported again from 1. Ask the number of the last people.
For example: n = 3, k = 2.2, first, then No. 1, and the last is No. 3.
Input
`2 numbers n and k, indicating n individuals, count to k. (2 <= n, k <= 10^6)`
Output
`The number of people left last left`
input example
`3 2`
OUTPUT Example
`3`

It feels that mathematical problems are so difficult …

The

analysis process is like this. Assuming that the first round is eliminated by the person number K-1 (the number starts from 0), then there will be a mapping relationship between the first and second rounds.

k —————–>0

k+1————–>1

n-1—————>n-k-1

0——————>n-k

k-2 ——————–> N-2 (the first round on the left, the second round on the right)

Set x as the number in the second round. According to the mapping above, there will be such a relationship (x+k)%n. The reason why N-1 individuals were mapped from the second round to the first round of N individuals.

and k = m%n, and the formula can be obtained (x+m)%n.

and pushing this way, from the second round to the third round, it is (x+m)%(n-1), so that it is recursor to the end.

I can think of the last round, there is only one person left, then he is the winner, the number is 0.

So according to the above relationship, push back, get the last round of the number 0 number in the first round, is the answer.

``````#include <iostream>
#include <cstdio>
#include <cstring>
#define  MAX_N 1000005
using namespace std;
int main()
{
int n,k;
int f[MAX_N];
while(cin>>n>>k)
{
f=0;
for(int i=2;i<=n;i++)
{
f[i]=(f[i-1]+k)%i;
}
printf("%d\n",f[n]+1);
}
return 0;
}
``````

source