-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 输出小于100的斐波那契数列 | ||
# 代码学习: 这里的b相当于是当前位置的数,而a每次都保存了前一次的值 | ||
print('小于100的斐波那契数列') | ||
a = 0 | ||
b = 1 | ||
while b < 100: | ||
print(b, end = " ") | ||
a, b = b, a + b | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 求整数的几何级数 | ||
# 等比数列求和公式: Sn = a(1-q**n)/(1-q) | ||
|
||
print('几何级数') | ||
a = int(input('a:')) | ||
q = int(input('q:')) | ||
n = int(input('n:')) | ||
|
||
sum = a*(1-q**n)/(1-q) | ||
|
||
print(sum) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 暴力求解:质数只有1和本身是自己的因数,所以从2到本身减一去全部试探一遍 | ||
# 搜索到i**0.5就可以了 | ||
|
||
import time | ||
import math | ||
print('100万以内的质数') | ||
start = time.time() | ||
num = int(input('number:')) | ||
ret = [] | ||
l = [2, 3, 5, 7, 9] | ||
for i in range(2, num+1): | ||
for a in l: | ||
if i%a == 0: | ||
continue | ||
|
||
for j in range(2, int(i**0.5)): | ||
if i%j == 0: | ||
break | ||
else: | ||
ret.append(i) | ||
|
||
print('Counts:', len(ret)) | ||
print('Time:', time.time()-start) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.