当前位置:网站首页>[weekly pit] information encryption + [answer] positive integer factorization prime factor
[weekly pit] information encryption + [answer] positive integer factorization prime factor
2022-07-06 20:19:00 【Crossin's programming classroom】
Zero basis python Introductory tutorial :python666.cn
Hello everyone , Welcome to Crossin Programming classroom of !
Today, I'll give you one of my favorite topics : Information encryption
Of course , This problem is the fur of information encryption .
Please listen to :
A yuan and Qiqi pass notes in class , But I don't want to be found by others . So they agreed on an encryption method :
Only for English or Pinyin in the information content ( That's the letter ) To encrypt , Other symbols remain intact
Each letter moves backward 5 position , Become ciphertext , such as a->f,k->p
If backward 5 More than z, Just fold back to the beginning of the letter , such as x->c
Please complete the encryption and decryption of this rule with a piece of code .
The reference sample :
【 encryption 】
Input :there is a vegetable in your teeth
Output :ymjwj nx f ajljyfgqj ns dtzw yjjym
【 Decrypt 】
Input :onz sn mzf izt
Output :jiu ni hua duo
Additional questions
Can you decrypt this text :
ild gdpsh sxktgvts xc p ldds, pcs x--
x iddz iwt dct athh igpktats qn,
pcs iwpi wph bpst paa iwt sxuutgtcrt.
Detailed answers and reference codes will be given in the next column , You can also refer to the code in the message of other students .
I look forward to your answers , I hope you can complete the whole series .
Simple code can be submitted directly in the message , Long code is recommended paste.ubuntu.com or
codeshare.io And other code sharing sites , Just copy the code and save it , You can get a share address , Very convenient .
For past questions, click the collection at the beginning of the article “ Every Monday ” Enter the view .
【 answer 】 Positive integer factorization prime factor
The original title is :【 Every Monday 】 Positive integer factorization prime factor
One idea of this question is :
from 2 Start trying to divide the original number N
If you can divide , The original number is updated to N//i, And the output i; If you can't divide it, keep trying , until N Divide by itself
If there is a prime factor before , The last remaining i Is the last prime factor ; without , It shows that the original number is a prime number
The reason why there is no need to judge the divisor i Is it a prime number , Because i It's from 2 Start trying one by one , If it can be divided by a smaller number , Then it has been dealt with before . So what can be calculated i It must be the prime factor .
In addition, here is a small optimization point : Every time you try, you don't have to start from 2 Start , You can start with the previous prime factor .
Reference code :
n = input(' Enter the positive integer to be decomposed :')
start = 2
is_prime = True
while n > 1: # Keep breaking down n, Until it breaks down into 1
for index in range(start, n + 1) :
if n % index == 0: # n Can be index to be divisible by
n //= index # n=n//index
if n == 1:
if is_prime:
print(f'{index} Prime number ')
else:
print(index)
else: # index It must be prime
print(f'{index} * ', end='')
is_prime = False
break
start = index
_ Previous articles are recommended _
If you need to know Paid premium courses And Teaching Q & a service
Please be there. Crossin Programming classroom of Internal reply : 666
边栏推荐
猜你喜欢
Oceanbase Community Edition OBD mode deployment mode stand-alone installation
Maximum likelihood estimation and cross entropy loss
RT thread I2C tutorial
永磁同步电机转子位置估算专题 —— 基波模型与转子位置角
Trends of "software" in robotics Engineering
Node. Js: express + MySQL realizes registration, login and identity authentication
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
夏志刚介绍
腾讯T4架构师,android面试基础
Event center parameter transfer, peer component value transfer method, brother component value transfer
随机推荐
Method keywords deprecated, externalprocname, final, forcegenerate
深度学习分类网络 -- ZFNet
【云小课】EI第47课 MRS离线数据分析-通过Flink作业处理OBS数据
Rhcsa Road
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development
recyclerview gridlayout 平分中间空白区域
Le lancement du jupyter ne répond pas après l'installation d'Anaconda
【GET-4】
夏志刚介绍
Rhcsa Road
Force deduction brush question - 98 Validate binary search tree
JVM_常见【面试题】
Poj1149 pigs [maximum flow]
An East SMS login resurrection installation and deployment tutorial
腾讯云数据库公有云市场稳居TOP 2!
[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN
5. 無線體內納米網:十大“可行嗎?”問題
JS get browser system language
B-杰哥的树(状压树形dp)