Given an array, find out who wins the game. DX vs DY.

 

DY and DX received an array generator on the occasion of Codigo and being the math buffs that they are, a math game was quickly formulated.  Consider an array A which consists of N elements A1,A2,...,AN. An index i of the given array is considered good if Ai=i.  DY wins the game if the count of good indices in the array is co-prime to the size of the array, while DX wins the other way around.  Given an array, find out who wins the game






OURSHOPKEEPER











#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{

    int Ni;
    int T;
    cin >> T;
    while (T--)
    {

        cin >> N;
        int a[N];
        int count=0;
        int p=0;
        for (int i = 0i < Ni++)
        {
            cin >> a[i];
        }
        for (int i = 0i < Ni++)
        {
            p++;
            if (a[i] == p) // a1 ==  0 a2  == 1 a3 == 2 a4 == 3 a5 4 a6 5
                count++;
        }
        if(__gcd(count,N)==1)
        cout<<"DY"<<endl;
        else
        cout<<"DX"<<endl;

    }}





    


Click on the above button to download the code.



Post a Comment

If you have furthur QUERIES please let us know

Previous Post Next Post