Files
python/TangDou/LianXiTi50/43_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
744 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
/*
题目求0—7所能组成的奇数个数。 (可重复 0不能做首位)
思路: 0-7能重复 统计1位,2位,3位, 4位, 5位, 6位,7位,8位,每个位数的奇数个数
1位 4 1357
2位 7*4 =4*7 最后一位是4种那么首位就是除了0就是8-1=7个乘法原理7*4=28个
3位 7*4*8
4位 7*4*8*8
5位 7*4*8*8*8
6位 7*4*8*8*8*8
7位 7*4*8*8*8*8*8
8位 7*4*8*8*8*8*8*8
*/
int main() {
//加一位和两位的个数
int cnt = 4 + 4 * 7;
int x = 8;
//从3到8
for (int i = 3; i <= 8; i++) {
cnt += 7 * 4 * x;
x = x * 8;
}
printf("%d\n", cnt);
return 0;
}