当前位置:网站首页>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)
边栏推荐
- That is, after the negative impact of gcat advertising e-commerce, is there no stable advertising e-commerce platform?
- Project analysis of Taishan crowdfunding mode: why is Taishan crowdfunding mode so popular?
- 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
- 在产业互联网的概念刚刚出现时,人们仅仅只是将其看成是一个获取B端流量的方法
- [cloud native | kubernetes] kubernetes configuration
- Uploading and retrieving stored images in localstorage
- Smart finance is upgraded again, and jinglianwen technology provides data collection and labeling services
- 105. constructing binary trees from preorder and inorder traversal sequences
- The new retail market has set off blind box e-commerce. Can the new blind box marketing model bring dividends to businesses?
- 号称下一代监控系统 来看看它有多牛逼
猜你喜欢
Tikv key performance parameters and optimization
Gold jewelry enterprise operation mode, beautiful tiantians business solution
Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge
基于ESP32CAM实现WebSocket服务器实时点灯
【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真
Application of DS18B20 temperature sensor based on FPGA
通过函数seaborn.cubehelix_palette生成顺序调色板
Lightning breakpoint continuation
How to use Wangyou DFM software for cold plate analysis
如何使用望友DFM軟件進行冷板分析
随机推荐
基于ESP32CAM实现WebSocket服务器实时点灯
The new retail market has set off blind box e-commerce. Can the new blind box marketing model bring dividends to businesses?
Periodontitis investigation (ongoing)
我的理财产品显示清算中是什么意思?
10 Honest Facts I Want To Share With All Junior Developers
尝试使用RenderDoc查看UE的Shader代码
Gold jewelry enterprise operation mode, beautiful tiantians business solution
快速排序
2022-06-12:在N*N的正方形棋盤中,有N*N個棋子,那麼每個格子正好可以擁有一個棋子。 但是現在有些棋子聚集到一個格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二維數組代錶,一
玄武云科技通过上市聆讯:业绩波动明显,陈永辉等三人为控股股东
微隔离(MSG)
Lightning data import
Will the chain 2+1 model be a new business outlet and a popular Internet e-commerce market?
Upper computer development (software test of firmware download software)
Application of DS18B20 temperature sensor based on FPGA
Why is the new e-commerce outlet mode so popular? What is the specific mode?
FSM state machine
Continuous management design
【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真
数字时代进化论