1 回答
TA贡献3593条经验 获得超0个赞
TA贡献2条经验 获得超0个赞
#include <stdio.h>
int main()
{
int n,m,i,j,k,max,number,array[1000];
j = 0;
scanf_s("%d%d", &n, &m);
i = n;
if (m == n)
{
number = i;
while (number % 2 == 0)
number /= 2;
while (number % 3 == 0)
number /= 3;
while (number % 5 == 0)
number /= 5;
if (number == 1)
{
printf("%d", n);
return 0;
}
else
{
printf("%d %dNO", n, m);
return 0;
}
}
else
{
for (i = n; i <= m; i++)
{
number = i;
while (number % 2 == 0)
number /= 2;
while (number % 3 == 0)
number /= 3;
while (number % 5 == 0)
number /= 5;
if (number == 1)
{
array[j] = i;
j++;
k = j;
}
else
number = 0;
}
}
if (number == 1)
{
for (i = n; i <= m; i++)
{
for (j = 0; j < k; j++)
if (array[j + 1] > array[j])
max = array[j + 1];//最大丑数
}
printf("%d", max);
}
if (number == 0)
printf("%d %dNO", n, m);
return 0;
}除了可能的溢出问题,以及时间复杂度等考虑,算是勉强解决了这一问题吧(我还小,嘿嘿)。。。。
TA贡献2条经验 获得超0个赞
#include <stdio.h>
int main()
{
int n,m,i,j,k,max,number,array[1000];
j = 0;
scanf_s("%d%d", &n, &m);
for (i = n; i <= m; i++)
{
number = i;
while (number % 2 == 0)
number /= 2;
while (number % 3 == 0)
number /= 3;
while (number % 5 == 0)
number /= 5;
if (number == 1)
{
array[j] = i;
j++;
k = j;
}
}
for (i = n; i <= m; i++)
{
for(j=0;j<k;j++)
if (array[j + 1] > array[j])
max = array[j + 1];
}
printf("%d", max);
return 0;
}评论改的代码格式。。。。[n,m]范围内最大丑数求解代码,应该没问题,目前在想如何加上无丑数输出no的情况
用的number代替i来给丑数输入数组,但是如何改变number或者再添加一个变量使得number(number=0或者A=number时A=0使得printf(“%d”,max)跳过,而输出printf(“no”)
- 1 回答
- 0 关注
- 1698 浏览
添加回答
举报