标题:带分数
100 可以表示为带分数的形式:100 = 3 + 69258 / 714
还可以表示为:100 = 82 + 3546 / 197
注意特征:带分数中,数字1~9分别出现且只出现一次(不包含0)。
类似这样的带分数,100 有 11 种表示法。
题目要求:
从标准输入读入一个正整数N (N<1000*1000)
程序输出该数字用数码1~9不重复不遗漏地组成带分数表示的全部种数。
注意:不要求输出每个表示,只统计有多少表示法!
例如:
用户输入:
100
程序输出:
11
再例如:
用户输入:
105
程序输出:
6
100 可以表示为带分数的形式:100 = 3 + 69258 / 714
还可以表示为:100 = 82 + 3546 / 197
注意特征:带分数中,数字1~9分别出现且只出现一次(不包含0)。
类似这样的带分数,100 有 11 种表示法。
题目要求:
从标准输入读入一个正整数N (N<1000*1000)
程序输出该数字用数码1~9不重复不遗漏地组成带分数表示的全部种数。
注意:不要求输出每个表示,只统计有多少表示法!
例如:
用户输入:
100
程序输出:
11
再例如:
用户输入:
105
程序输出:
6
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cmath>
#define N 10005
#define inf 1e-101
using namespace std;
int flag[10];
int f(int x)
{
int y;
while(x)
{
y=x%10;
x/=10;
if(flag[y])
return 0;
flag[y]=1;
}
return 1;
}
int judge(int i,int j,int k)
{
if(!f(i)||!f(j)||!f(k))
return 0;
if(flag[0])
return 0;
for(int l=1;l<=9;l++)
{
if(flag[l]==0)
return 0;
}
return 1;
}
int main()
{
int n,cnt=0;;
scanf("%d",&n);
for(int i=1;i<n;i++)
{
for(int k=1;k<9999;k++)
{
int j=(n-i)*k;//n=i+j/k
memset(flag,0,sizeof(flag));
if(judge(i,j,k))
cnt++;
}
}
printf("%d\n",cnt);
return 0;
}