119A - Epic Game - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

def gcd(x,y):
    
    m = min(x,y)
    hcf = 0
    
    if x == 0 or y == 0:
        if x != 0:
            return x
        else:
            return y
    else:
        for i in range(1,m+1):
          if x%i == 0 and y%i == 0:
            hcf = i
        
        return hcf
 
a,b,n = map(int,input().split())
active = True
chance = 0
while active:
    t_s = gcd(a,n)
    n = n - t_s
    chance += 1
 
    if n <= 0:
        break
 
    t_as = gcd(b,n)
    n = n - t_as
    chance += 1
 
    if n <= 0:
        break
 
print(0 if chance%2 != 0 else 1)

C++ Code:

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

#define ll        long long

#define frp(a, b) for(ll i = a; i < b; i++)
#define frn(a, b) for(ll i = a; i > b; i--)

#define V2        vector < vector<ll> > v(n, vector <ll> (n));

#define in(x)     insert(x)
#define pb(x)     push_back(x)
#define full(x)   x.begin(),x.end()

void setup();
void solve();
void test();

int main()
{
	setup();
	// cout << "f" << endl;
	test();
	// solve();
	return 0;
}

void solve()
{
	//cout << "h" << endl;
	ll t; cin >> t;

	while(t--)
	{
		
		ll n; cin >>  n;

        
        vector <ll> v(n);

        frp(0, n) cin >> v[i];

       

	}
}

void test()
{
	ll a, b, n; cin >> a >> b >> n;


	bool simon = true;
	while(true)
	{
		if(n == 0) break;

		if(simon)
		{
			simon = (!simon);

			ll g = __gcd(a, n);
			n -= g;
		}
		else
		{
			simon = (!simon);

			ll g = __gcd(n, b);
			n -= g;
		}

	}

	if(simon) cout << "1" << endl;
	else cout << "0" << endl;

}
void setup()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
#endif
}


Comments

Submit
0 Comments
More Questions

1691B - Shoe Shuffling
1706A - Another String Minimization Problem
1695B - Circle Game
1702B - Polycarp Writes a String from Memory
1701A - Grass Field
489C - Given Length and Sum of Digits
886B - Vlad and Cafes
915A - Garden
356A - Knight Tournament
1330A - Dreamoon and Ranking Collection
1692B - All Distinct
1156C - Match Points
1675A - Food for Animals
1328C - Ternary XOR
1689A - Lex String
1708B - Difference of GCDs
863A - Quasi-palindrome
1478A - Nezzar and Colorful Balls
1581B - Diameter of Graph
404A - Valera and X
908A - New Year and Counting Cards
146A - Lucky Ticket
1594C - Make Them Equal
1676A - Lucky
1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA