zoukankan      html  css  js  c++  java
  • [CodeChef FEB15]Payton numbers(CUSTPRIM)解题报告

    题目

    (翻译来自洪华敦)
    定义三元组的乘法
    def multiply((a1,b1,c1), (a2,b2,c2)):
    s = (a1a2 + b1b2 + c1c2) + (a1b2 + b1a2) + (c1 + c2)
    t = floor[s/2] + 16(c1 + c2) - c1c2
    A = (t - 2(a1b2 + b1a2) - (a1c2 + c1a2) + 33(a1 + a2)+ (b1b2 - a1a2))
    B = (t - 5(a1b2 + b1a2) - (c1b2 + b1c2) + 33(b1 + b2)+ (2b1b2 + 4a1a2))
    if s is even: return (A-540,B-540,24)
    else: return (A-533,B-533,11)
    定义zero:若x*任何y=0,则称x是zero
    定义单位元,若x*任何y=y,则称x是单位元
    定义质数,若x不是zero且不能分解成两个非单位元的乘积,则称x是质数
    给定一个三元组,问他是不是质数

    题解

    CC上有自带的(英文)题解:
    还有一篇中文翻译:
    翻译有遗漏之处,以原文为准。反正我就是看CC上的英文题解看懂的。
    解法简直出(sang)神(xin)入(bing)化(kuang),大家还是去看原文吧……
    (没错这真的是一篇解题报告)

    代码

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    typedef long long LL;
    LL realmod(LL a,LL m){
    	a%=m;
    	if(a<0) a+=m;
    	return a;
    }
    inline LL quickmul(LL x,LL y,LL MOD){
    	x=realmod(x,MOD),y=realmod(y,MOD);
    	return ((x*y-(LL)(((long double)x*y+0.5)/MOD)*MOD)%MOD+MOD)%MOD;
    }
    LL quickpow(LL a,LL n,LL M){
    	a=realmod(a,M);
    	LL ans=1;
    	while(n){
    		if(n&1) ans=quickmul(ans,a,M);
    		a=quickmul(a,a,M);
    		n>>=1;
    	}
    	return ans;
    }
    LL Legendre_symbol(LL a,LL p){//p是奇素数 
    	//1代表a是平方剩余,-1代表a不是平方剩余,0代表a=0 
    	//a^((p-1)/2)
    	a=realmod(a,p);
    	LL flg=quickpow(a,(p-1)/2,p);
    	if(flg==0||flg==1) return flg;
    	if(flg==p-1) return -1;
    }
    bool Rabin_Miller(LL n,LL p){//合数返回0
    	if(n==2) return true;
    	if(n==1||(n&1)==0) return false;
    	LL d=n-1;
    	while(!(d&1)) d>>=1;
    	LL m=quickpow(p,d,n);
    	if(m==1) return true;
    	while(d<n){
    		if(m==n-1) return true;
    		d<<=1;
    		m=quickmul(m,m,n);
    	}
    	return false;
    }
    bool is_prime(LL n){//素数返回1
    	if(n==0||n==1) return false;
    	static int rm_primes[]={2,3,5,7,11,13,17,19,23,29,31};
    	for(int i=0;i<11;i++){
    		if(rm_primes[i]==n) return true;
    		if(!Rabin_Miller(n,rm_primes[i])) return false;
    	}
    	return true;
    }
    bool test(LL a,LL b,LL c){
    	LL A=33-2*a-c;
    	LL B=b-a;
    	if(B==0){
    		if(A==-2||A==2) return true;
    		if(is_prime(abs(A))){
    			if(Legendre_symbol(-11,abs(A))==-1) return true;
    		}
    		return false;
    	}
    	else{
    		return is_prime(A*A+A*B+3*B*B);
    	}
    	return false;
    }
    int main(void){
    	int T;
    	LL a,b,c;
    	scanf("%d",&T);
    	while(T--){
    		scanf("%lld%lld%lld",&a,&b,&c);
    		if(test(a,b,c)) printf("PRIME
    ");
    		else printf("NOT PRIME
    ");
    	}
    	return 0;
    }
    


  • 相关阅读:
    fill 全解(转)
    解题报告 疯狂的馒头
    解题报告 报数
    解题报告 noi 2005 智慧珠游戏(BT 搜索)
    解题报告 跑步
    解题报告 Punch
    解题报告 纪念日
    解题报告 新兵站队
    转载:让理科生沉默,让文科生流泪的综合题
    解题报告 信号放大器
  • 原文地址:https://www.cnblogs.com/wmdcstdio/p/7554224.html
Copyright © 2011-2022 走看看