当前位置:网站首页>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)
边栏推荐
- Through the function seaborn cubehelix_ Palette build order palette
- Database connection under WinForm
- Lightning breakpoint continuation
- Ansible PlayBook的中清单变量优先级分析及清单变量如何分离总结
- C drawing table and sending mail function
- Department store center supply chain management system
- Tidb grafana reverse proxy
- RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
- Implementation of fruit mall wholesale platform based on SSM
- 我的理财产品显示清算中是什么意思?
猜你喜欢

105. constructing binary trees from preorder and inorder traversal sequences

Eureka server multi node deployment

对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map

Evolution in the digital age
![[cloud native | kubernetes] kubernetes configuration](/img/cb/20595d34a9e203b83dd086cc27037d.png)
[cloud native | kubernetes] kubernetes configuration

WWDC2022最大的亮点: MetalFX

First day of learning MySQL Basics

【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真

测试开发程序员,你还在迷茫吗?不能把自己定义为码农......

上位机开发(固件下载软件之架构设计)
随机推荐
Eureka server multi node deployment
YOLOv5解析 | 参数与性能指标
Jinglianwen technology provides voice data acquisition and labeling services
数字时代进化论
Reflection of C # Foundation
Will the chain 2+1 model be a new business outlet and a popular Internet e-commerce market?
Detailed description of drawing ridge plot, overlapping densities of overlapping kernel density estimation curve, facetgrid object and function sns Kdeplot, function facetgrid map
The innovative public platoon mode team invites users to split, beautiful every second, and links the 2+1 new business model
15、 IO stream (I)
Differences between SQL and NoSQL of mongodb series
我的理财产品显示清算中是什么意思?
Tidb server tuning
Introduction and use of dumping
上位机开发(固件下载软件之软件测试)
如何从头自己制作开发板?图文并茂,一步步操作给你看。
Tikv key performance parameters and optimization
Tidb grafana reverse proxy
基于SSM实现水果商城批发平台
Try to use renderdoc to view the shader code of UE
Is it safe for Hangzhou Securities to open an account?