据说是一些版子

bool IsPrime[1000010];  
int Prim[1000010];  
int  euler_prime(int n){  
    int num = 0, j;  
    for(int i = 2; i <= n; i ++){  
        if(!IsPrime[i])  
            Prim[num ++] = i;  
        for(j  = 0; j < num; j ++){  
            if(i * Prim[j] > n)  
                break;  
            IsPrime[i * Prim[j]] = true;  
            if(i % Prim[j] == 0)  
                break;  
        }  
    }  
    //for(int i = 0; i < num; i ++){  
    //    cout << Prim[i] << endl;  
    //}  
}/*欧拉筛*/
#include <bits/stdc++.h>
//大素数的Miller-Rabin算法
using namespace std;

typedef long long ll;
//利用二进制计算a*b%mod
ll multiMod(ll a,ll b,ll mod){
    ll ret = 0LL;
    a %= mod;
    while( b ){
        if ( b & 1LL ) ret = ( ret + a ) % mod, --b;
        b >>= 1LL;
        a = ( a + a ) % mod;
    }
    return ret;
}

//计算a^b%mod
ll powerMod(ll a,ll b,ll mod){
    ll ret = 1LL;
    a %= mod;
    while( b ){
        if ( b & 1LL ) ret = multiMod(ret,a,mod),--b;
        b >>= 1LL;
        a = multiMod(a,a,mod);
    }
    return ret;
}

//Miller-Rabin测试,测试n是否为素数
bool Miller_Rabin(ll n,int repeat){
    if ( 2LL == n || 3LL == n ) return true;
    if ( !( n & 1LL ) ) return false;

    //将n分解为2^s*d
    ll d = n - 1LL;
    int s = 0;
    while( !( d & 1LL ) ) ++s, d>>=1LL;

    srand((unsigned)time(0));
    for(int i=0;i<repeat;++i){//重复repeat次
        ll a = rand() % ( n - 3 ) + 2;//取一个随机数,[2,n-1)
        ll x = powerMod(a,d,n);
        ll y = 0LL;
        for(int j=0;j<s;++j){
            y = multiMod(x,x,n);
            if ( 1LL == y && 1LL != x && n-1LL != x ) return false;
            x = y;
        }
        if ( 1LL != y ) return false;
    }
    return true;
}

int main(){
	ll n;
	while(~scanf("%lld",&n))
	{
		if ( Miller_Rabin(n,3) ) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
	return 0;
}
struct hash_table{
  ull seed;
  ull Hash[maxn],temp[maxn];
  void Set(ull num){
    seed=num;
  }
  void work(char *s,int n){
    temp[0]=1;
    Hash[0]=0;
    for(int i=1;i<=n;i++)temp[i]=temp[i-1]*seed;
    for(int i=1;i<=n;i++)Hash[i]=(Hash[i-1]*seed+(s[i]-'a'));
  }
  ull get(int l,int r){
  return Hash[r]-Hash[l-1]*temp[r-l+1];
  }
}h;
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = 1e6+5;

struct splaytree{
	int date;
}spt[maxn];

int fth[maxn],sn[maxn][2],num[maxn],size[maxn];
int sz,rt;

inline void clr(int x) {
	sn[x][0] = sn[x][1] = fth[x] = size[x] = num[x] = spt[x].date = 0;
}
inline void create(int x) { sz++; sn[x][0] = sn[x][1] = fth[x] = 0; num[x] = size[x] = 1; }
inline int whs(int x) { return sn[fth[x]][1] == x; }
inline void setson(int son,int f,int w) {
	if ( son != 0 ) fth[son] = f;
	if ( f != 0 ) sn[f][w] = son;
}
inline void maintain(int x) {
	size[x] = size[sn[x][0]] + size[sn[x][1]] + num[x];
}

inline void rotate(int x) {
	int f = fth[x]; int ff = fth[f]; int w = whs(x); int wf = whs(f);
	int p = sn[x][!w];
	setson(p,f,w); setson(x,ff,wf); setson(f,x,!w);
	maintain(f); maintain(x);
}

inline void splay(int x) {
	for (;fth[x];rotate(x)) {
		if ( fth[fth[x]] && whs(fth[x]) == whs(fth[fth[x]])) 
			rotate(fth[x]);
	}
	rt = x;
}

inline void insert(int x) {
	if ( rt == 0 ) {
		create(x); rt = sz; return;
	}
	int now = rt , f = 0;
	while(true) {
		if ( x == spt[now].date ) {
			num[now]++; maintain(now); maintain(f); splay(now); break;
		} f = now; now = sn[now][spt[now].date < x];
		if(now == 0 ) {
			create(x); fth[sz] = f;
			sn[f][spt[f].date<x] = sz; spt[sz].date = x;
			maintain(f); splay(sz);
			break;
		} 
	}
}

inline int find(int x) {
	int ans = 0,now = rt;
	while (true) {
		if ( x < spt[now].date ) now = sn[now][0];
		else {
			ans += sn[now][0] ? size[sn[now][0]] : 0;
			if ( x == spt[now].date ) {
				splay(now); return ans + 1;
			} ans += num[now]; now = sn[now][1];
		} 
	}
}

inline int Kth(int x) {
    int now = rt;
    while(1){
        if(sn[now][0] && x <= size[sn[now][0]]) now = sn[now][0];
        else{
            int tmp = (sn[now][0] ? size[sn[now][0]] :0) + num[now];
            if(x <= tmp) return spt[now].date;
            x -= tmp;
            now = sn[now][1]; 
        }
    }
} 

inline int pre() {
	int now = sn[rt][0];
	while(sn[now][1]) now = sn[now][1];
	return now;
}

inline int nxt() {
	int now = sn[rt][1];
	while(sn[now][0]) now = sn[now][0];
	return now;
}

int main() {
	int n,op,x;
	return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
 
const int N = 200010;
char s[N], str[N*2];
int p[N*2];
int manacher()
{
    int i;
    for(i = 1; s[i]; i++)
        str[i*2] = s[i], str[i*2+1] = '#';
    str[0] = '?', str[1] = '#', str[i*2] = '\0';
    int res = 0, k = 0, maxk = 0;
    for(int i = 2; str[i]; i++)
    {
        p[i] = i < maxk ? min(maxk - i, p[2*k-i]) : 1;
        while(str[i-p[i]] == str[i+p[i]]) p[i]++;
        if(p[i] + i > maxk)
            k = i, maxk = i + p[i];
        res = max(res, p[i]); // manacher
    }
    return res - 1;
}
 
int main()
{
    while(~ scanf(" %s", s + 1))
        printf("%d\n", manacher());
 
    return 0;
}

 

posted @ 2018-04-30 20:01  Nlifea  阅读(134)  评论(0编辑  收藏  举报