当前位置:网站首页>HJ质数因子
HJ质数因子
2022-06-28 07:36:00 【有勇气的牛排】
描述
功能:输入一个正整数,按照从小到大的顺序输出它的所有质因子(重复的也要列举)(如180的质因子为2 2 3 3 5 )
数据范围:1≤n≤2×109+14
输入描述:
输入一个整数
输出描述:
按照从小到大的顺序输出它的所有质数的因子,以空格隔开。
示例1
输入:180
输出:2 2 3 3 5
质数因子解释:
百度百科:https://baike.baidu.com/item/%E8%B4%A8%E5%9B%A0%E5%AD%90/10720836?fr=aladdin
概念:
- 一个数可以被它所有的质因子表示
解法:
- 质数范围一定在 根号下n
- n除以所有质因子,结果为1:24/2/2/2/3=1
牛客HJ Python
import math
n = int(input())
for i in range(2, int(math.sqrt(n) + 1)):
while n % i == 0:
print(i, end=" ")
n = n // i
# 打印剩下的质数
if n > 2:
print(n)
原文链接:
边栏推荐
- Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
- No suspense about the No. 1 Internet company overtime table
- Leetcode+ 66 - 70 high precision, two sub topics
- 2021 VDC: technological architecture evolution of vivo Internet service for 100 million users | PPT download attached
- Unity UI shadow component
- R 和 rgl 绘制 3D 结
- OPC 协议认识
- R language hitters data analysis
- 云原生(待更新)
- Kubelet garbage collection (exiting containers and unused images) source code analysis
猜你喜欢

腾讯下半年继续裁员,所有事业群至少缩减 10%,对此你怎么看?关注者

扩展Prometheus的解决方案thanos的简介和几个月使用心得

ABAP skill tree

Design and practice of vivo sensitive word matching system

2021 programming language ranking summary

MySQL installation steps - Linux configuration file JDK installation (II)

2021 VDC: technological architecture evolution of vivo Internet service for 100 million users | PPT download attached

Safety training is the greatest benefit for employees! 2022 induction safety training for new employees

Analyze 5 indicators of NFT project

A gadget can write crawlers faster
随机推荐
R 语言绘制 动画气泡图
Kubernetes cluster lossless upgrade practice
Analyze 5 indicators of NFT project
XML serialization backward compatible
Leetcode+ 66 - 70 high precision, two sub topics
Devtools implementation principle and performance analysis practice
Source code analysis of kubernetes' process of deleting pod
Huawei cloud computing physical node cna installation tutorial
pip 更新到最新的版本
MMR rearrangement (similarity is calculated by editing distance and repeatability)
Llvm and clang
Sentinel mechanism of redis cluster
Makefile
MySQL master-slave replication, detailed configuration, create unable to connect processing prompt
R language ggmap
Design and practice of vivo sensitive word matching system
vite2.9 中指定路径别名
Practice of traffic recording and playback in vivo
Practice and exploration of vivo live broadcast application technology
Self discipline challenge 30 days