CF633A Ebony and Ivory

CF633A Ebony and Ivory

洛谷传送门

题意翻译

给定三个数a,b,c 判断不定方程 a * x + b * y == c 是否有整数解。存在输出“Yes”,否则为“No”。 @yyy2015c01

翻译提供者:龙_之_谷


题解:

一般这种题都是枚举一个未知量判第二个未知量是不是整数。

重点有三:

第一:确定拿谁表示谁。

第二:确定枚举范围。

第三:确定判断条件。

剩下的就直接做就好了。

代码:

#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int a,b,c;
char nmsl[6];
int main()
{
	// freopen("yesterday.in","r",stdin);
	// freopen("yesterday.out","w",stdout);
	scanf("%d%d%d",&a,&b,&c);
	int mx=max(a,b);
	int mxx=c/mx+1;
	for(int i=0;i<=mxx;i++)
	{
		int p=i*mx;
		if(p>c)
			break;
		if((c-p)%(a+b-mx)==0)
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}
posted @ 2020-11-22 17:19  Seaway-Fu  阅读(75)  评论(0编辑  收藏  举报