当前位置:网站首页>2021-03-04 comp9021 class 6 notes
2021-03-04 comp9021 class 6 notes
2022-06-24 08:22:00 【Purple cloud without dike】
List of articles
review
Get the ASCII code
Sort
lambda expression
Classic questions - Prime factor - Prime Factor
Give a positive integer , Print out the prime factor of the number .
I don't know what a prime factor is , Look here Prime factor , Prime factor .
from math import sqrt
def primeFactors(m):
'''return the prime factors of the input number m '''
prime_factors = [] # Used to store prime factors
factor = 2 # The smallest prime factor
upper_bound = int(sqrt(n)) # The upper limit of the factor of a number
while factor <= upper_bound: # from 2 Start traversing to the upper limit
while m % factor == 0: # Determine whether the current value is a factor
m //= factor
prime_factors.append(factor)
factor += 1
if m != 1:# If the last number is not 1, Then this number is also a prime factor # Thanks for the reminder from wow le , Modified here
prime_factors.append(m) # Put yourself in the results
prime_factors = [str(x) for x in prime_factors]
return f"{n} = {'*'.join(prime_factors)}"
n = 231084
print(primeFactors(n))
Number of statistical prime factors
from math import sqrt
def primeterFactorInfo(m):
prime_factors = {
}
factor = 2
upper_bound = int(sqrt(n))
while factor <= upper_bound:
while m % factor == 0:
m //= factor
if factor not in prime_factors:
prime_factors[factor] = 1
else:
prime_factors[factor] += 1
factor += 1
if m != 1:# If the last number is not 1, Then this number is also a prime factor # Thanks for the reminder from wow le , Modified here
prime_factors[m] = 1
return prime_factors
n = 5432
primeterFactorInfo(n)
Count the number of prime factors collections.counter
Precision problem - precision
A reminder from Mr. Luo :
This round It's not round off as mentioned above , Sometimes I give up and sometimes I go in , It is python The precision of the decimal representation of itself .
The test and official documentation are as follows
- Test accuracy
The following code is the result of each line ( Except for the equation ) All output , and matlab almost .
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'
Calculation n The prime number within
Calculate program run time
- timeit modular
Official documents :timeit - Calculate the running time of a small code module - globals function
globals The function returns all global variables of the current environment . stay timeit This function can avoid the trouble of manually entering parameters .
Official documents : At the bottom of the page , the last one
Use... In the program :
边栏推荐
- Coordinate transformation of graphic technology
- transformers PreTrainedTokenizer类
- 【点云数据集介绍】
- Online education fades
- The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain
- Synthesize video through ffmpeg according to m3u8 file of video on the network
- 软件过程与项目管理期末复习与重点
- 疫情下更合适的开发模式
- Leetcode 207: course schedule (topological sorting determines whether the loop is formed)
- 51单片机_外部中断 与 定时/计数器中断
猜你喜欢
Swift foundation features unique to swift
Écouter le réseau d'extension SWIFT (source)
Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)
3D数学基础[十七] 平方反比定理
Search and recommend those things
Synthesize video through ffmpeg according to m3u8 file of video on the network
How to use the virtual clock of FPGA?
Pat 1157: school anniversary
2022 PMP project management examination agile knowledge points (1)
Question 4 - datepicker date selector, disabling two date selectors (start and end dates)
随机推荐
Vulnhub target: boredhackerblog: social network
Synthesize video through ffmpeg according to m3u8 file of video on the network
软件工程导论——第三章——需求分析
Swift 基礎 閉包/Block的使用(源碼)
贷款五级分类
Understanding of the concept of "quality"
2022茶艺师(中级)上岗证题库及在线模拟考试
2021-03-16 COMP9021第九节课笔记
新准则金融资产三分类:AMC、FVOCI和FVTPL
[teacher zhaoyuqiang] use the Oracle tracking file
JVM underlying principle analysis
Model effect optimization, try a variety of cross validation methods (system operation)
Five level classification of loans
JS scroll div scroll bar to bottom
Swift Extension NetworkUtil(網絡監聽)(源碼)
根据网络上的视频的m3u8文件通过ffmpeg进行合成视频
13 -- remove invalid parentheses
[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA
C language_ Love and hate between string and pointer
搜索与推荐那些事儿