633A - Ebony and Ivory - CodeForces Solution


brute force math number theory *1100

Please click on ads to support us..

Python Code:

a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)

f = 0

for i in range(10000):
    ai= a*i

    if ai>c:
      break
  
    remaining= c-a*i

    if remaining%b==0:
      print("YES")
      f= 1
      break

if f == 0:
    print("NO")

   					 		   	   					 	 				

C++ Code:

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<cctype>
#include<set>
#include<unordered_set>
#include<cstring>
#include<numeric>
#include<limits>
#include<limits.h>
#include<bitset>
#include<list>
using namespace std;
#define ll long long
#define pb push_back
#define Fifo ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int c2=c;
    while(c>0)
    {

        if(c%b==0)
        {
            cout<<"Yes";
            return 0;
        }
        c-=a;
    }
    while(c2>0)
    {

        if(c2%a==0)
        {
            cout<<"Yes";
            return 0;
        }
        c2-=b;
    }
    cout<<"No";
}




























































bool isPrime(ll n) {
    if (n <= 1)
        return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;

    return true;
}
// function to find a substring in a string
int isSubstring(string s1, string s2)
{
    if (s2.find(s1) != string::npos)
        return s2.find(s1);
    return -1;
}
//function to find gcd using Euclid's algorithm
int gcd(int n1, int n2)
{
    if (n2 != 0)
        return gcd(n2, n1 % n2);
    else
        return n1;
}
// Function to find gcd of array of n numbers
int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if (result == 1)
        {
            return 1;
        }
    }
    return result;
}
//function return the number of distinct characters in a string O(s.length())
int function(string s)
{
    int sum = 0;
    int freq[26] = { 0 };
    for (int i = 0; i < s.length(); i++)
    {
        freq[s[i] - 'a']++;
    }
    for (int i = 0; i < 26; i++)
    {
        if (freq[i] > 0)
            sum++;
    }
    return sum;
}
//function returns the sum of the digits of a number
int getSum(int n)
{
    int sum = 0;
    while (n != 0) {
        sum = sum + n % 10;
        n = n / 10;
    }
    return sum;
}

	 	    	     	  				 	 	  	  		


Comments

Submit
0 Comments
More Questions

1091A - New Year and the Christmas Ornament
1352B - Same Parity Summands
1102A - Integer Sequence Dividing
630B - Moore's Law
1004A - Sonya and Hotels
1680B - Robots
1690A - Print a Pedestal (Codeforces logo)
1295A - Display The Number
1077A - Frog Jumping
1714G - Path Prefixes
1369C - RationalLee
289B - Polo the Penguin and Matrix
1716A - 2-3 Moves
1670B - Dorms War
1716B - Permutation Chain
987A - Infinity Gauntlet
1676G - White-Black Balanced Subtrees
1716D - Chip Move
1352F - Binary String Reconstruction
1487B - Cat Cycle
1679C - Rooks Defenders
56A - Bar
1694B - Paranoid String
35A - Shell Game
1684A - Digit Minimization
43B - Letter
1017A - The Rank
1698B - Rising Sand
235A - LCM Challenge
1075B - Taxi drivers and Lyft