样例输⼊ 2
样例输出 2
主要难的是转这么多进制,求哪位思考下
假定 是幸运数字返回true 不是返回false
进制转换 你输入的咱默认十进制
while(n)
{
a[i++]=n%10;
n/=10
}
把每一位存到数组
遍历数组
先判断有没有 0 如果有 直接return false
然后呢
再写个函数 判断是否五进制是否幸运数字 有0返回false
进制转换不过是短除法,, 把余数直接存数组就行了 一样的遍历判断方法
之后类似 我写好了是否幸运数字的判断 你再写个循环找数字 就ok了 对了 我不会c++语法 自己看着改
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define True 1
#define False 0
int jinzhi(int n,int j)
{
int a[10],i=0;
int temp = n;
while (temp)
{
a[i++] = temp % j;
temp /= j;
}
for (i = 0;i < 10;i++)
if (a[i] == 0)
return False;
return True;
}
int isLuck(int n)
{
//五 七 九进制判断 全真和为3 不是3 说明不是幸运数字
if (jinzhi(n, 5) + jinzhi(n, 7) + jinzhi(n, 9) != 3)
return False;
else
return True;
}
int main()
{
int n;
printf("十进制输入一个数n:");
scanf("%d", &n);
if(isLuck(n))
printf("是幸运数字");
else
printf("不是幸运数字");
return 0;
}
建一个通用的转数制函数
def tran(n,m):
res = ''
while n:
res = str(n%m) + res
n //= m
return res
a,b = map(int,input().split())
total = 0
for i in range(a,b+1):
if '0' not in tran(i,5)+tran(i,7)+tran(i,9):
total += 1
print(total)
#include<bits/stdc++.h>
using namespace std;
int jz(int b)
{
int a=b;
while(a!=0)
{
if(a%5==0)
return 0;
a/=5;
}
a=b;
while(a!=0)
{
if(a%7==0)
return 0;
a/=7;
}
a=b;
while(a!=0)
{
if(a%9==0)
return 0;
a/=9;
}
return 1;
}
int main()
{
int n,m,tot=0;
cin>>n>>m;
for(int i=n;i<=m;i++)
{
if(jz(i))
tot++;
}
cout<<tot;
return 0;
}