11,799
社区成员




```c
#include<stdio.h>
int main()
{
int i = 0;
int ret = 0;
for (i = 10000; i < 99999; i++)
{
if ((i % 3 == 0) && (i % 10 == 6))
{
ret++;
}
}
printf("%d", ret);
return 0;
}
```
注意,是五位数一共有多少,所以要从10000开始
//java写法
public static void main(String[] args) {
int j = 0;
for (int i = 10000; i < 99999; i++) {
if(i%3 == 0 && String.valueOf(i).endsWith("6")){
j++;
System.out.println(i);//输入可以被3整除的数
}
}
System.out.println(j);//一共有多少个
}
个位数限定为6,且6也能被3整除,所以问题简化为:求前4位的数能否被3整除即可
python代码:
>>> len([i for i in range(1000,10000) if not i%3])
3000
添加了一点,把数给输出出来了。
count = 0
for i in range(10000, 100000):
a = i % 10
b = i % 3
if a == 6 and b == 0:
count = count + 1
print(i, end="\t")
if count % 10 == 0:
print()
print(count)
#include <stdio.h>
int main()
{
/* Write C code in this online editor and run it. */
int count = 0;
int base = 10002;
while(base + 3 < 100000)
{
if((base % 10) == 6)
{
count++;
}
base += 3;
}
printf("count is %d \n", count);
return 0;
}
3000