Choose Integers

中石油6549(拓展)

We ask you to select some number of positive integers, and calculate the sum of them.
It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.
Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.
If the objective is achievable, print YES. Otherwise, print NO.

Constraints
1≤A≤100
1≤B≤100
0≤C<B

输入

Input is given from Standard Input in the following format:
A B C

输出

Print YES or NO.

样例输入

7 5 1

样例输出

YES

提示

For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.

数据量太小可以暴力

暴力代码;

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#define mod 20123
#define inf 123456789
#define LL long long
#define big 1e18
#define mem(a,b) memset(a,b,sizeof(a))
using  namespace std;
int max( int a, int b){ return a>b?a:b;}
int maxn ( int a, int b, int c){ return max(max(a,b),max(b,c));}
LL min(LL a,LL b){ return a<b?a:b;}
int main()
{
     int a,b,c;
     scanf ( "%d%d%d" ,&a,&b,&c);
     for ( int i=1;i<=b;i++)
     {
         if (i*a%b==c)
         {
             printf ( "YES\n" );
             return 0;
         }
     }
     printf ( "NO\n" );
     return 0;
}

乘法逆元(不知为什么,中石油不过,但codver就过)

ax≡c mod f;gcd(a,f)==c

#include<stdio.h>
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int main()
{
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   if(gcd(a,b)==c) printf("YES\n");
   else printf("NO\n");
   return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_41485193/article/details/80385220