This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
/*
题目:求0—7所能组成的奇数个数。 (可重复 0不能做首位)
思路: 0-7能重复 统计1位,2位,3位, 4位, 5位, 6位,7位,8位,每个位数的奇数个数
1位 4 (1,3,5,7)
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;