Circle of chaos - Help

Please help me solve my mistake. Circle of chaos,
Basic Pseudocode:

  1. For all entries in array “p”, take the
    minmod = minimum((pi % n))
    Then, print (n - minmod)??

I passed all example test case, but got WA.
Here is my solution.

Any idea about this
get the minimum next left you can kill, suppose 3rd ,now you kill him 4th becomes 3rd, kill him next becomes 3rd…so on…until next person is me.
So in short you can kill everyone after the minimum you can kill

     #include <bits/stdc++.h> 
     using namespace std; 

    typedef long long ll;

    int main() 

    ll t;


    ll n,m;


    ll A[m];
    for(int i=0;i<m;i++)

    ll mn = n;
    for(int i=0;i<m;i++)
    if(A[i]%n == 0)
    mn = min(A[i]%n, mn);

    cout<<(n - mn)<<"\n";


    return 0; 
1 Like

Did you get WA too??

In case of
9 2
6 9
It should be 6 not 3

always give some information with you code like how u tried to solve it … it will help the person reading your code otherwise its really difficult

My code gives 6, still

7 2
7 9
Answer 6

1 Like

Ok sir

How come? After first round selecting 6, there would be 8, 7,6 . So max you can kill is 3??

can you show it on paper?

  1. calculate gcd of all M numbers
  2. find divisors of above gcd
  3. X = from divisior take that divisor which is just less than equal to N
  4. print(N - X)

@reena_code_123 can you please tell us that whether your code is working or not??

no after that
1,7 2,8 3,9 4,10 5,11 6,12
u can kill 3rd sorcerer as it has value 9 then continue the process

I have, NOT WORKING, still thinking what case it fails on

Ahh…the value of mod itself changes everytime!! Damn!

Are youthoob wala bro, can you tell why my code fails?
I did similar to this but instead of doing this one time i am doing this for several times,
Approach: find minimum of (arr[i]%n) (if arr[i]%n !=0) otherwise take minimum of arr[i] only then add (n-minimum obtained) in the answer and repeat this step until we get the (minimum found >=n).
Please Help! I am stuck here from 2 hrs !!

I did only calculate the gcd of all numbers.If gcd>n then n-1 else n-gcd. What is wrong in this approach? . Can u give a test case?

7 2
7 5

5 2
12 24

your code output: 4
correct output: 1

1 Like