[大数分解板子] 2020ccpc 威海 D

题目

应该之后会放gym的吧 大致是求n(n<=1e18)的质因子的积

代码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
const int INF = 0x3f3f3f3f;
const int S=8;
long long mult_mod(long long a,long long b,long long c){
	a%=c;
	b%=c;
	long long ret = 0;
	long long tmp = a;
	while(b){
		if(b&1){
			ret+=tmp;
			if(ret>c)  ret-=c;
		}
		tmp<<=1;
		if(tmp>c) tmp-=c;
		b>>=1;
	}
	return ret;
}
long long pow_mod(long long a,long n,long long mod){
	long long ret=1;
	long long temp = a%mod;
	while(n){
		if(n&1) ret=mult_mod(ret,temp,mod);
		temp=mult_mod(temp,temp,mod);
		n>>=1;
	}
	return ret;
} 
bool check(long long a,long long n,long long  x,long long t){
	long long ret=pow_mod(a,x,n);
	long long last=ret;
	for(int i=1;i<=t;i++){
		ret=mult_mod(ret,ret,n);
		if(ret==1&&last!=1&&last!=n-1) return true;
		last=ret;
	}
	if(ret!=1) return true;
	else return false;
}
bool Miller_Rabin(long long n){
	if(n<2) return false;
	if(n==2) return true;
	if((n&1)==0) return false;
	long long x=n-1;
	long long t=0;
	while((x&1)==0){
		x>>=1;
		t++;
	}
	srand(time(NULL));
	for(int i=0;i<S;i++){
		long long a=rand()%(n-1)+1;
		if(check(a,n,x,t)) return false;
	}
	return true;
}
long long factor[100];
int tol;
long long gcd(long long a,long long b){
	long long t;
	while(b){
		t=a;
		a=b;
		b=t%b;
	}
	if(a>=0) return a;
	else return -a;
}
long long pollard_rho(long long x,long long c){
	long long i=1,k=2;
	srand(time(NULL));
	long long x0=rand()%(x-1)+1;
	long long y=x0;
	while(1){
		i++;
		x0=(mult_mod(x0,x0,x)+c)%x;
		long long d=gcd(y-x0,x);
		if(d!=1&&d!=x) return d;
		if(y==x0) return x;
		if(i==k){
			y=x0,k+=k;
		}
	}
}
void findfac(long long n,int k){
	if(n==1) return ;
	if(Miller_Rabin(n)){
		factor[tol++]=n;
		return ;
	}
	long long p=n;
	int c=k;
//	cout<<1<<endl;
	while(p>=n) p=pollard_rho(p,c--);
		findfac(p,k);
		findfac(n/p,k);
	//cout<<2<<endl; 
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		long long c;
		cin>>c;
		tol=0;
		findfac(c,107);
		sort(factor,factor+tol);
		int m=unique(factor,factor+tol)-factor;
		long long res=1;
		for(int i=0;i<m;i++){
			res*=factor[i];
		//	cout<<factor[i]<<" "<<endl;
		}
		//cout<<res<<endl;
		if(res>=c) cout<<"no"<<endl;
		else cout<<"yes"<<endl;
	}
    return 0;
	}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值