当前位置:网站首页>[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

边栏推荐
- Anaconda安裝後Jupyter launch 沒反應&網頁打開運行沒執行
- Is it difficult for small and micro enterprises to make accounts? Smart accounting gadget quick to use
- 【每周一坑】输出三角形
- BUUCTF---Reverse---easyre
- JVM_ Common [interview questions]
- OceanBase社区版之OBD方式部署方式单机安装
- 【Yann LeCun点赞B站UP主使用Minecraft制作的红石神经网络】
- 【GET-4】
- Period compression filter
- Node.js: express + MySQL实现注册登录,身份认证
猜你喜欢

Cesium 点击绘制圆形(动态绘制圆形)

【每周一坑】信息加密 +【解答】正整数分解质因数

02 basic introduction - data package expansion

OceanBase社区版之OBD方式部署方式单机安装

01 基础入门-概念名词

案例 ①|主机安全建设:3个层级,11大能力的最佳实践

Learn to punch in Web

Tencent byte Alibaba Xiaomi jd.com offer got a soft hand, and the teacher said it was great

爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解

Case ① | host security construction: best practice of 3 levels and 11 capabilities
随机推荐
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
Ideas and methods of system and application monitoring
Gui Gui programming (XIII) - event handling
JVM_ Common [interview questions]
Guangzhou's first data security summit will open in Baiyun District
【GET-4】
[cloud lesson] EI lesson 47 Mrs offline data analysis - processing OBS data through Flink
某东短信登录复活 安装部署教程
案例 ①|主机安全建设:3个层级,11大能力的最佳实践
为什么新手在编程社区提问经常得不到回答,甚至还会被嘲讽?
Trends of "software" in robotics Engineering
Catch ball game 1
Maximum likelihood estimation and cross entropy loss
腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发
[network planning] Chapter 3 data link layer (3) channel division medium access control
深度学习分类网络 -- ZFNet
In unity space, an object moves around a fixed point on the sphere at a fixed speed
Rhcsa Road
腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
New generation garbage collector ZGC