muhou
发表于 2018-4-11 11:03:38
def main(a):
for i in range(2,a):
if(a % i == 0):
return i
elif(i == (a-1)):
return 0
End_Print =''
if __name__ == '__main__':
Input_Num = a = int(input())
End_Print += '%s = '%a
while main(a):
End_Print += '%s * '%main(a)
a = int(a / main(a))
End_Print += '%s'%a
if '%d = %d'%(Input_Num,Input_Num) == End_Print:
print('%d是素数'%Input_Num)
else:
print('%d不是素数'%Input_Num)
print(End_Print)
echoC
发表于 2018-4-13 14:46:42
本帖最后由 echoC 于 2018-4-13 17:35 编辑
num2=num1=int(input('请输入一个正整数:'))
list1 = []
for i in range(2,num2+1):
if num2>=i:
if num2%i ==0:
while num2%i==0:
num2=num2/i
list1.append(i)
list1.sort()# 排下序
print('%d=%d' % (num1, list1), end='')
for i in range(1, len(list1)):
print('*%d' % list1, end='')
天天学习$
发表于 2018-4-24 18:42:49
def prime_number(number):
'''判断一个数是否为素数,1代表素数,0代表合数'''
list0 = []
list1 = []
for j in range(1,(number + 1)):
if number % j == 0:
list1.append(j)
if len(list1) == 2:
list0.append(number)
return 1
else :
return 0
number = int(input('请输入一个数:'))
list4 = []
while prime_number(number) == 1 or number == 1:
number = int(input('此数字是素数或者为1请重新输入:'))
while prime_number(number) == 0:
for i in range(1,number + 1):
if number % i == 0 and i != number and i != 1:
list4.append(i)
number //= i
break
list4.append(number)
print(list4)
小庆子
发表于 2018-4-29 21:06:20
a = []
n = int(input('请输入数字:'))
def dec_factor(n):
for i in range(2,n+1):
if n%i == 0:
a.append(i)
dec_factor(n//i)
return n
break
else:
continue
return a
dec_factor(n)
print('%s = '%n,end='')
for i in a[:-1]:
print(i,end='*')
print(a[-1])
萧丹夜
发表于 2018-5-8 21:36:46
from math import sqrt
a = []
def fabor(n):
if n == 1:
return 1
else:
global a
i = int(sqrt(n)+1)
for k in range(2,i+1):
if n % k == 0:
a.append(k)
return fabor(n//k)
a.append(n)
print(a)
x = int(input('请输入一个正数:'))
fabor(x)
张大哈
发表于 2018-6-14 10:34:36
n = int(input("请输入一个整数:"))
print(n,end='=')
k = 2
while k != n:
if n%k == 0:
print(k,end='*')
n /= k
else:
k = k+1
print(int(n))
还不会写递归
892427369
发表于 2018-7-18 22:25:38
b = int(input("请输入一个正整数:"))
c = b
print(b,"=",sep="",end="")
for d in range(2,b):
if c % d == 0:
print(d,end="")
c = int(c/d)
break
while True:
for e in range(2,c+1):
if c % e ==0:
print("*",e,sep="",end="")
c = int(c/e)
break
892427369
发表于 2018-7-18 22:38:56
892427369 发表于 2018-7-18 22:25
b = int(input("请输入一个正整数:"))
c = b
print(b,"=",sep="",end="")
补一个break,否则死循环了。
b = int(input("请输入一个正整数:"))
c = b
print(b,"=",sep="",end="")
for d in range(2,b):
if c % d == 0:
print(d,end="")
c = int(c/d)
break
while True:
for e in range(2,c+1):
if c % e ==0:
print("*",e,sep="",end="")
c = int(c/e)
break
if c == 1:
break
Akihisa
发表于 2018-8-16 09:55:52
n = int(input('请输入一个正整数:'))
if n == 1:
print('1既不是质数也不是合数,无法进行质因数分解!')
i = 2
while i <= n:
if n%i == 0:
print(i)
n = n//i
else:
i += 1
子沙
发表于 2018-8-22 10:52:18
def fun_9(num):
num1=num
i=2
m=[]
while i<num:
if num%i==0:
m.append(str(i))
num=num/i
i=1
i+=1
m.append(str(int(num)))
print('%u='%(num1),end='')
print('*'.join(m))
fun_9(1024)
不可进行质因数分解的正整数会直接输出,如‘2=2’
一步半个脚印
发表于 2018-8-23 17:12:44
from math import sqrt
import sys
n=int(input("Please input number:"))
if n ==1:print('Please get out!!')
for k in range(2, int(sqrt(n))+1):
while (n%k==0):
print(k),
n=n/k
if n==1:sys.exit(0) #出现n=1的情况需要去除
print(n)
嘎嘎嘎就是这么好看。。。
acgods
发表于 2018-8-23 19:03:18
# num = int(input("请输入一个大于1的正整数:"))
num = 100
if num <=1:
print("输入错误")
else:
print("%d=" % num,end="")
i = 2
while i <= num:
if num % i == 0:
print("%d" % i,end=" ")
num = num / i
else:
i += 1
d2nte
发表于 2018-8-31 09:54:42
def prime(n):
ls =
for num in range(2,n+1):
for d in range(2,num):
if num%d == 0: break
if d== num - 1:
ls.append(num)
op = str(n)+" = "
for c in range(n):
if n == 1:
break
for k in ls:
if k == n:
op += str(k)
n /= k
break
elif n%k == 0:
n /= k
op += str(k) + "*"
break
return print(op)
while True:
n = int(input("please input the number:"))
prime(n)
if input("continue?") == "no": break
测试了一下大数运算时比较慢,学习大家的代码改进一下
sxzpf
发表于 2018-9-11 18:51:38
i = 1
while i>0:
n = int(input('请输入一个正整数:'))
if n <= 0:
print('这不是正整数,请重新输入:')
elif n == 1:
print(n,'=',n)
else:
print(n,'=',end = '')
while n>1:
for k in range(int(2),int(n+1)):
if n%k==0:
print(k,end = '')
n/=k
break
k+=1
if n>1:
print('*',end = '')
i+=1
print()
apple_wt
发表于 2018-9-14 11:04:03
num = input("请输入一个正整数:")
num1 = int(num)
i = 2
while i <num1:
if num1%i==0:
num1 /=i
print(i,end="*")
else:
i +=1
print(int(num1))
zhengsc
发表于 2018-9-30 22:42:25
n = int(input("输入n:"))
str1 =str(n)+" = "
k=2
while k < n+1:
if n%k == 0:
str1 = str1 +str(k)+'*'
n = n/k
else:
k=k+1
str1=str1
print(str1)
zhangjk19841984
发表于 2018-10-20 16:05:25
import math
n=int(input("请输入一个正整数:"))
a=[]
k=2
str1=str(n)+'='
for i in range(k,n+1):
if n>=k:
if n%i==0:
a.append(i)
n=n/i
k+=1
if i<n:
str1+=str(i)+'*'
else:
str1+=str(i)
else:
break
print(str1)
Roc乘风
发表于 2018-10-25 14:25:49
打卡,说一下遇到的问题,不能初始化for 循环参数
i = 1
for n in range(1,10):
i =(i + 1) * 2
print(i)
i = 1
d = 3
for _ in range(9):
i += d
d *= 2
print(i)
Q爸爸
发表于 2018-10-25 16:31:27
num = 345678
k =2
while num >= k:
if num%k ==0:
num = num/k
print(k)
else:
k+=1
liujian973
发表于 2018-11-15 17:14:45
def divide_factor(n):
def factor(number):
import math
sqrt = int(math.sqrt(number))
for i in range(2,sqrt+1):
if number % i ==0:return i
return False
temp = factor(n)
if temp == False:
print(n)
else:
print(temp)
divide_factor(int(n/temp))