1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| Number Rotations
Consider the number 142857. We can right-rotate this number by moving the last digit (7) to the front of it, giving us 714285. It can be verified that 714285=5×142857. This demonstrates an unusual property of 142857: it is a divisor of its right-rotation.
Find the last 5 digits of the sum of all integers n, 10 < n < 10^{100}, that have this property.
数字轮换
考虑数142857,我们可以将它的数字右移一位并把最后一个数字7放到最前面,得到714285。 可以验证714285=5×142857。 这表明了142857的一个特殊性质:它右移一位并把末位数字移至最前得到的数是它的倍数。
找出所有10 < n < 10^{100}范围内满足这一性质的整数n,求它们的和的最后五位数字。
我的思路:
设
* (n) 是一个 **L 位十进制整数**(首位非零) * 右移一位(末位移到最前)得到 (R(n)) * 存在整数 (k\ge2),使得 [ R(n) = k n ]
记 [ n = 10a + d \quad (d\in{0,\dots,9}) ] 则 [ R(n) = d\cdot 10^{L-1} + a ]
代入条件: [ d\cdot 10^{L-1} + a = k(10a + d) ]
化简得 [ (10k-1)a = (10^{L-1}-k)d ]
于是 [ a = d\cdot \frac{10^{L-1}-k}{10k-1} ]
我下面的代码不知道为什么找不到142857这个解,请修正
lim=10**100 mod=100000
res=0
def blen(n,b): res=0 while(n>0): n//=b res+=1 return res
def chk(num): l=blen(num,10) nnum=num//10+(num%10)*(10**(l-1)) if(nnum%num==0): # print('!') # print(num) # print(nnum) # print() return True return False
for d in range(1,10): for l in range(1,101): for k in range(1,10): upper=10**(l-1)-k lower=10*k-1 if(upper%lower==0): num=d*(upper//lower) num=num*10+d if num>lim: break if(chk(num) and num>10): # print(num) res+=num res%=mod
print(res)
|