当前位置:网站首页>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)
原文链接:
边栏推荐
- Huawei cloud computing physical node cna installation tutorial
- Llvm and clang
- Vivo browser rapid development platform practice - Overview
- Spark 离线开发框架设计与实现
- Alibaba cloud server creates snapshots and rolls back disks
- Detailed explanation of collection class methods____ (4) Judgment and assignment, etc
- MySQL installation steps - how to create a virtual machine under Linux (1)
- Mysql8.0和Mysql5.0访问jdbc连接
- 推荐系统系列精讲(第五讲): 排序模型的调优实践
- Practice and exploration of vivo live broadcast application technology
猜你喜欢

How bacnet/ip gateway collects data of building centralized control system

What is a consistent hash? What scenarios can it be applied to?

云原生(待更新)

Leetcode learning records

在idea中,get和set方法爆红可能是没有安装Lombok插件

Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)

剑指Offer||:链表(简单)

kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑

HTTP Caching Protocol practice

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
随机推荐
What should I do if the version is incompatible with the jar package conflict?
Llvm and clang
LLVM 与 Clang
代码提交规范
8 figures | analyze Eureka's first synchronization registry
Jinshan cloud team shared | 5000 words to understand how Presto matches with alluxio
MMR rearrangement (similarity is calculated by editing distance and repeatability)
ABAP 技能树
Evolution of vivo push platform architecture
Uninstall and reinstall the latest version of MySQL database. The test is valid
mysql57 zip文件安装
Code submission specification
Unity-UI-shadow组件
QT -- communication protocol
Modifying MySQL port number under Linux
Principle and practice of bytecode reference detection
OPC 协议认识
Ice - resources
力扣515.在每棵树行中找最大值
kubernetes删除pod的流程的源码简析