Blue Bridge cup title abcde / fghij = n

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

Blue Bridge Cup title

abcde/fghij=n

Title Description

abcde/fghij=n,其中a~j为数字0~9的不重复的排列,这里的除为整除,
请统计这样的组合一共有多少个?

Source title

#include<stdio.h>

int judge(int a,int b)         //判断两个数是不是由十个数字排列组合而成
{
	int p[10]={11};           //设置一个数组,用来存放数字;初始化数组,数组中不能出现的数值至少应该大于等于十,否则会对接下来的求位数造成干扰;
	int m=0;                 //过度变量
	for(int i=0;i<5;i++)     //用循环的方法依次求出五位数a的各个位数
	{
		
		m=a%10;            //求余,取余数
		p[m]=m;           //将对应的数字放到数组中对应的位置,如a[1]=1
		a=a/10;          //求下一位的数字
	}
	for(int j=0;j<5;j++)          //求形参b的各位数字
	{
		m=b%10;
		p[m]=m;
		b=b/10;
	}
	for(int k=0;k<10;k++)       //判断a和b的各位数字是否有重复
	{
		if(p[k]!=k)          //若有重复,则必有a[n]=11;其中n属于0-9;
		return 0;
	}
	return 1;            //若各位数字都不同,则返回1
}
 
int main()
{
	int n,i;
	int sum=0;       //累计次数,并初始化
	for(i=2;i<=79;i++)     //求i范围内的循环
	    for(n=1234;n*i<=98765;n++)        //嵌套循环,两个五位数相除变为分母乘以商,并控制循环范围
		if(judge(n,i*n))      //判断
		    sum=sum+1;
	printf("%d\n",sum);
}

Test Results

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_43876206/article/details/93376913