Question: Hello, can you please help take a look at this code and revise it? Basically, it exceeds the time limit on the system, but I
Hello, can you please help take a look at this code and revise it? Basically, it exceeds the time limit on the system, but I am not sure how to improve this code. Thank you.
#includeusing namespace std; void josephus(int n, int m){ int arr[n]; for (int i = 0; i n m; josephus(n, m); return 0; }
Josephus Problem Description n individuals labeled from 1 to 71 form a circle, which means the next person of the nth person is the first person. Counting begins at the first person, and the mth person counted will go out. Then the counting restart at the next person of the one who went out, and still the mth person counted will go out. Repeat the counting until all of the people have gone out. It's a famous problem and you can seek for some detailed information on wikipedia. In this problem, given an and m, please show the order they went out. Input A single line containing two integers n and m separated by a space. Output Print an integers in a single line denoting the labels of these n. persons and indicating the order they went out. Please separate each two of these integers by a single space. Sample Input/Output Input 103 Output 36927185104 Constraint 1 g n, m g 104. Hint 0(nm) algorithm can pass through all test cases
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
