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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值