鱼C论坛

 找回密码
 立即注册
查看: 1827|回复: 1

题目130:求合数n,使得n-1能够被能整除n的最小循环整数的长度整除

[复制链接]
发表于 2016-8-23 17:17:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Composites with prime repunit property

A number consisting entirely of ones is called a repunit. We shall define R(k) to be a repunit of length k; for example, R(6) = 111111.

Given that n is a positive integer and GCD(n, 10) = 1, it can be shown that there always exists a value, k, for which R(k) is divisible by n, and let A(n) be the least such value of k; for example, A(7) = 6 and A(41) = 5.

You are given that for all primes, p > 5, that p − 1 is divisible by A(p). For example, when p = 41, A(41) = 5, and 40 is divisible by 5.

However, there are rare composite values for which this is also true; the first five examples being 91, 259, 451, 481, and 703.

Find the sum of the first twenty-five composite values of n for which
GCD(n, 10) = 1 and n − 1 is divisible by A(n).


题目:

如果一个数全部由 1 组成,称之为一个循环整数。定义 R(k) 为长度为k的循环整数,例如 R(6) = 111111。

已知 n 是正整数以及 GCD(n, 10) = 1,可以证明,总存在一个 k 值使得 R(k) 可以被 n 整除,用 A(n) 表示这些 k 值中最小的,例如 A(7) = 6,A(41) =5。

已知对于所有大于 5 的质数 p,p-1 能够被 A(p) 整除。例如,当 p=41 时,A(41)=5,40 可以被 5 整除。

但是,有一些罕见的合数也满足整个条件;前五个例子是 91, 259, 451, 481 和 703。

求前 25 个满足 GCD(n, 10) = 1 以及 n-1 能被 A(n) 整除的合数 n 之和。

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-7-19 14:32:13 | 显示全部楼层
from math import gcd
def A(n):
        if gcd(n, 10) != 1: return 0
        x, k = 1, 1
        while x != 0:
                x = (x*10+1) % n
                k += 1
        return k
primes = [True]*1000000
primes[:2] = [False]*2
for i,prime in enumerate(primes):
        if prime:
                for j in range(i*i, 1000000, i):
                        primes[j] = False
count = 0
s = 0
i = 2
while True:
        if not primes[i] and gcd(i, 10) == 1 and (i-1)%A(i)==0:
                count += 1
                s += i
        if count == 25:
                break
        i += 1
print(s)
149253
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-7-2 21:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表