HDU 1197 Specialized Four-Digit Numbers

其实就是之前刷过的一道题:SKY数,传送门:

https://blog.csdn.net/qq_39459939/article/details/83184667

#include <stdio.h>
#include <math.h>

int calSumInSomeSystem(int DecNum, int System)
{
	int sum = 0;
	int a = DecNum, b=System;
	int c = 0;
	while(a != 0)
	{
		c = a%b;
		a = a/b;
		sum+=c;
	}
	return sum;
}

void main()
{
	int m = 1000;
	while(m < 10000)
	{
		int sum1 = calSumInSomeSystem(m,16);
		int sum2 = calSumInSomeSystem(m,12);
		int sum3 = calSumInSomeSystem(m,10);

		if(sum1 == sum2 && sum2 == sum3)
			printf("%d\n",m);
		m++;
	}
	return;
}

 

相关文章: