当前位置:网站首页>Number of detection cycles "142857“
Number of detection cycles "142857“
2022-06-13 07:05:00 【Flying bird immortal】
describe
If one n The string of digits satisfies the following conditions , It is called a cyclic number (cyclic): Treat this string of numbers as an integer ( May have a leading 0), And use any one 1 To n Between ( contain 1 and n) When you multiply it by an integer of , You will get a string that connects the beginning and end of the original string , The integer corresponding to the new number string obtained by disconnecting at some place . for example , Numbers 142857 It's the number of cycles , because :
142857 *1 = 142857
142857 *2 = 285714
142857 *3 = 428571
142857 *4 = 571428
142857 *5 = 714285
142857 *6 = 857142.
Please write a program to judge whether a given number is a circular number .
Be careful : In this question , The input string can be preceded 0, And leading 0 Can't be ignored , for example “01” Is a two digit string , and “1” Is a string of digits . But when converting a number string to an integer for multiplication or comparison , You can ignore the leading 0.
python The advantage is that it supports large number calculation , If it is C++ You need to write your own functions to add, subtract, multiply and divide large numbers ;
Ideas :
1) Write a function to verify , Whether two numbers are the same after being shifted ; The cycle of violence is used here to compare ;
2) Write a function to do 2 ~ len(s) Multiplication of , Each multiplication result is converted to a string , And use 0 Prefix complement length ; Compare whether it is the same after shifting ;
# 0 <= n <= len(s)
def numShift(s, n):
d = s[n:] + s[:n]
return d
# check string is same with s1,
def checkSame(s, s1):
#print("-----------------check same----------------")
for i in range(1, len(s)):
d = numShift(s, i)
#print("%d, %s" % (i, d))
if (s1 == d):
return True
return False
# check cycle num with multi by [2... len(num)]
def checkNum(num):
for i in range(2, len(num)+1):
newNum = int(num) * i
num1 = str(newNum).zfill(len(num)) # Front completion 0
print("%s * %d = %s" % (num, i, num1) )
if False == checkSame(num, num1):
return False
return True
b = checkNum("253968")
#b = checkNum("142857")
#b = checkSame("142857", "714285")
print(b)
边栏推荐
- Project analysis of Taishan crowdfunding mode: why is Taishan crowdfunding mode so popular?
- ISIS的vsys(虚拟系统)
- Tidb index optimization
- RT thread simulator lvgl control: button button style
- Tidb execution plan -- II
- Database connection under WinForm
- RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
- 考研英语
- 基于SSM实现水果商城批发平台
- 2022 - 06 - 12: dans un échiquier carré n * N, il y a n * n pièces, donc chaque pièce peut avoir exactement une pièce. Mais maintenant quelques pièces sont rassemblées sur une grille, par exemple: 2 0
猜你喜欢

Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge

Host computer development (Architecture Design of firmware download software)

MySQL系列之分库分表学习笔记

Br backup test

号称下一代监控系统 来看看它有多牛逼

RT thread simulator lvgl control: switch switch button control

Recently, the popular social e-commerce marketing model, blind box e-commerce, how beautiful every second is accurately drained

基于SSM实现水果商城批发平台

Why is the blind box e-commerce mode so popular?

如何从头自己制作开发板?图文并茂,一步步操作给你看。
随机推荐
关于c#委托、事件相关问题
Project analysis of Taishan crowdfunding mode: why is Taishan crowdfunding mode so popular?
检测循环数“142857“
Why is the blind box e-commerce mode so popular?
. Net code to implement get request and post request
New Taishan crowdfunding business diversion fission growth model in 2022
Department store center supply chain management system
如何使用望友DFM軟件進行冷板分析
RT thread simulator lvgl control: button button style
Introduction and use of dumping
线程池中的 工作线程如何被回收
RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
[RS-422 and RS-485] RS-422 and RS-485 serial interface standard
数字时代进化论
同花顺可以开股票账户吗?安全吗?
RT thread simulator lvgl control: switch switch button control
Chain 2+1 reward, what kind of mode is beautiful everyday seconds?
c#高级编程-特性篇
Eureka server multi node deployment
How to make a development board from scratch? Illustrated and illustrated, step by step operation for you to see.