You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求能被7整除但不含数字7的三位数个数的高效解法问询

求能被7整除但不含数字7的三位数个数的高效解法问询

Hey Angeline! I totally get it—going through every single three-digit number to check those two conditions sounds like a huge time-suck. Let me break down a much more efficient, math-based approach that avoids brute-force checking:

Step 1: Calculate total three-digit numbers divisible by 7

First, find the smallest three-digit number divisible by 7: that's 105 (since 7×15=105). The largest is 994 (7×142=994). To get the total count, subtract the multipliers and add 1 (since we’re including both endpoints):
142 - 15 + 1 = 128
So there are 128 three-digit numbers divisible by 7 in total.

Step 2: Subtract numbers that are divisible by 7 and contain the digit 7

We’ll split this into three mutually exclusive cases (so no double-counting) using basic number theory:

  • Case 1: Hundreds digit is 7
    These are numbers from 700 to 799 divisible by 7. The smallest is 700 (7×100) and largest is 798 (7×114). Count:
    114 - 100 + 1 = 15

  • Case 2: Tens digit is 7, hundreds digit is NOT 7
    Let the number be A7B (A ≠7, B is 0-9). This number equals 100A +70 + B, which can be rewritten as 7×(14A+10) + 2A + B. For the whole number to be divisible by 7, 2A + B must be divisible by 7. Testing valid values of A (1-6,8-9), we find 8 valid numbers: 175,273,371,476,574,672,875,973.

  • Case 3: Units digit is 7, hundreds and tens digits are NOT 7
    Let the number be AB7 (A≠7, B≠7). This equals 100A +10B +7, or 7×(14A+B+1) + 2A +3B. For divisibility by 7, 2A+3B must be divisible by 7. Testing valid A and B values, we get 8 valid numbers:147,217,357,427,567,637,847,917.

Adding these up: 15 +8 +8 =31 total numbers that are divisible by 7 but contain the digit 7.

Step3: Get the final count

Subtract the invalid numbers from the total:
128 -31 =97

If you want a quick sanity check, you can run a simple brute-force script to verify:

valid_count = 0
for num in range(100, 1000):
    if num %7 ==0 and '7' not in str(num):
        valid_count +=1
print(valid_count)

This will output 97, matching our math-based result.

备注:内容来源于stack exchange,提问作者Angeline0320

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 14:57:32