HDU 2009 整除的尾数 题解

Problem Description
一个整数,仅仅知道前几位,不知道末二位。被还有一个整数除尽了。那么该数的末二位该是什么呢?
 

Input
输入数据有若干组,每组数据包括二个整数a,b(0<a<10000, 10<b<100),若遇到0 0则处理结束。
 

Output
相应每组数据,将满足条件的全部尾数在一行内输出,格式见样本输出。

同组数据的输出。其每一个尾数之间空一格。行末没有空格。

 

Sample Input
200 40 1992 95 0 0
 

Sample Output
00 40 80 15

后面两位。目測,推断得最大只是100,那么能够暴力搜索了。

模拟:直接把后面两位的数值接上,然后測试能否够除尽。


#include <stdio.h>

int main()
{
	int a, b;
	while (scanf("%d %d", &a, &b) && (a || b))
	{
		bool flag = false;
		for (int i = 0; i < 10; i++)
		{
			int t = a * 10 + i;
			for (int j = 0; j < 10; j++)
			{
				int r = t * 10 + j;
				if (r % b == 0)
				{
					if (flag) putchar(' ');
					printf("%d%d", i, j);
					flag = true;
				}
			}			
		}
		putchar('
');
	}
	return 0;
}


或者直接使用模的特性来做:

#include <stdio.h>

int main()
{
	int a, b;
	while (scanf("%d %d", &a, &b) && b)
	{
		a = a * 100 % b;
		if (a) a = b - a;	//须要加上一个数才干整除
		printf("%02d", a);
		while ((a += b) && a < 100)
		{
			printf(" %02d", a);
		}
		putchar('
');
	}
	return 0;
}



原文地址:https://www.cnblogs.com/yfceshi/p/6857590.html