- 注册时间
- 2008-2-6
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 51573
- 在线时间
- 小时
|
发表于 2009-10-10 15:00:42
|
显示全部楼层
/*
(x * 100 + 11) == 0 mod p
x * 100 == p - 11 mod p
p = 3
x * 100 == 3 - 2 mod 3
x == 1 mod 3
p = 7
x * 100 == 7 - 4 mod 7
x * 2 == 3 mod 7
x == 5 mod 7
p = 11
x * 100 == 0 mod 11
x == 0 mod 11
p > 11
x * 100 + 11 == 0 mod p
x * 100 == (p - 11) mod p
x == (p - 11) * 100^(-1) mod p
*/
#include
#include
#define MAX 100000000
#define SieveNumber 65536
int Prime[9999];
int Cache[SieveNumber];
int P;
int P11[MAX];
int g = 0;
/*
ExtendedEuclid(e,f)
1 (X1,X2,X3):=(1,0,f)
2 (Y1,Y2,Y3):=(0,1,e)
3 if (Y3=0) then return e'=null//无逆元
4 if (Y3=1) then return e'=Y2 //Y2为逆元
5 Q:=X3 div Y3
6 (T1,T2,T3):=(X1-Q*Y1,X2-Q*Y2,X3-Q*Y3)
7 (X1,X2,X3):=(Y1,Y2,Y3)
8 (Y1,Y2,Y3):=(T1,T2,T3)
9 goto 3
*/
int inv100(int p)
{
int e = 100, f = p;
int X1 = 1, X2 = 0, X3 = f;
int Y1 = 0, Y2 = 1, Y3 = e;
int Q, T1, T2, T3;
while (1)
{
Q = X3 / Y3;
T1 = X1 - Q * Y1; T2 = X2 - Q * Y2; T3 = X3 - Q * Y3;
X1 = Y1; X2 = Y2; X3 = Y3;
Y1 = T1, Y2 = T2, Y3 = T3;
if (Y3 == 0) return (0);
if (Y3 == 1) return (Y2 % p);
}
}
void init()
{
int i;
Prime[0] = 2;
Prime[1] = 3;
Prime[2] = 5;
Prime[3] = 7;
Prime[4] = 11;
Prime[5] = 13;
for (i = 0; i < MAX; i ++)
P11[i] = 1;
}
void sieve()
{
int i, j, p;
for (i = 0; i <= 10; i ++)
Cache[i] = 0;
for (i = 12; i <= SieveNumber-1; i += 2)
Cache[i] = 0;
for (i= 11; i <= SieveNumber-1; i += 2)
Cache[i] = 1;
for (j = 1; j <= 5; j ++)
for (i = Prime[j] * Prime[j]; i <= SieveNumber-1; i += 2 * Prime[j])
Cache[i] = 0;
p = 6;
for (i = 16; i <= 256; i ++)
if (Cache[i] == 1)
Prime[p++] = i;
for (j = 6; j < p ; j ++)
for (i = Prime[j] * Prime[j]; i <= SieveNumber-1; i += 2 * Prime[j])
Cache[i] = 0;
for (i = 256; i <= SieveNumber-1; i ++)
if (Cache[i] == 1)
Prime[p ++] = i;
P = p;
}
void initP11()
{
int i, j, k;
for (i = 1; i < MAX; i += 3)
P11[i] = 0;
for (i = 5; i < MAX; i += 7)
P11[i] = 0;
for (i = 11; i < MAX; i += 11)
P11[i] = 0;
for (j = 5; j < P; j ++)
{
k = (Prime[j] - 11) * inv100(Prime[j]) % Prime[j];
for (i = k; i < MAX; i += Prime[j])
P11[i] = 0;
}
for (i = 1; i < P; i ++)
if ((Prime[i] >= 11) && ((Prime[i] - 11) % 100 == 0))
P11[(Prime[i]-11)/100] = 1;
}
void checkP11()
{
int i;
int prev = 0;
for (i = 0; i < MAX; i ++)
if (P11[i] == 1)
{
if ((i - prev) > g)
{
g = i - prev;
printf("Find: %d, start %d!\n", g - 1, (prev + 1));
}
prev = i;
}
}
int main()
{
init();
sieve();
initP11();
checkP11();
return (0);
}
/*
Find: 1, start 1!
Find: 4, start 4!
Find: 5, start 10!
Find: 7, start 43!
Find: 10, start 145!
Find: 14, start 361!
Find: 16, start 448!
Find: 20, start 652!
Find: 21, start 4347!
Find: 22, start 5605!
Find: 26, start 6217!
Find: 31, start 8083!
Find: 34, start 8452!
Find: 41, start 23284!
Find: 43, start 44875!
Find: 44, start 46711!
Find: 49, start 80101!
Find: 51, start 175623!
Find: 54, start 220659!
Find: 65, start 357075!
Find: 70, start 1239046!
Find: 78, start 4225245!
Find: 98, start 4242612!
Find: 99, start 7135851!
Find: 124, start 23717773!
*/ |
|