Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
44 lines (38 loc) · 772 Bytes

File metadata and controls

44 lines (38 loc) · 772 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding:utf-8 -*-
__author__ = 'gjw'
__time__ = '2018/1/11 0011 上午 10:48'
# 题目:求0—7所能组成的奇数个数。
"""
程序分析:
组成1位数是4个。
组成2位数是7*4个。
组成3位数是7*8*4个。
组成4位数是7*8*8*4个。
"""
# 使用规律计算
if __name__ == '__main__':
sum1 = 4
s = 4
for j in range(2, 9):
print(sum1)
if j <= 2:
s *= 7
else:
s *= 8
sum1 += s
print('sum = %d' % sum1)
# 使用递归
def f(n):
if n == 0:
return 1
elif n == 1:
return 7
else:
return f(n-1)*8
l = []
# 算出每位数有多少奇数
for i in range(1, 9):
l.append(f(i-1)*4)
print(l)
# 输出一共有多少个奇数
print(sum(l))
Morty Proxy This is a proxified and sanitized view of the page, visit original site.