博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TOJ 4383: n % ( pow( p , 2) ) ===0
阅读量:7052 次
发布时间:2019-06-28

本文共 1935 字,大约阅读时间需要 6 分钟。

4383: n % ( pow( p , 2) ) ===0 分享至QQ空间

Time Limit(Common/Java):10000MS/30000MS     Memory Limit:65536KByte
Total Submit: 237            Accepted:54

Description

 

There is a number n , determine whether there is a p (p>1) that p^2 is a divisor of n.

 

Input

 

The first line contains an integer T , the number of test case.

The following T lines , each contains an integer n.

( 1<= T <=10^2 , 1<= n <=10^18 )

 

Output

 

A integer p , if there exist multiple answer ,output the minimum one.

Or print “oh,no.” .

 

Sample Input

 

3

8
16
17

Sample Output

 

2

2
oh,no.

Source

这个题是错了一个数据,最后我去修了这个数据并加强了,好开心

就是问一下一个数是不是一个素数的平方,这个题的思路比较简单,就是一个大数的素数分解,直接搞一个miller_rabin的素数检测,再来一个pollard_rho大数分解质因数就好的

那个判断次数一般选20

#include
#include
#include
#include
#include
#include
using namespace std;typedef __int64 ll;const int times=20;const int N=100;ll mult_mod(ll a,ll b,ll mod){ a%=mod; b%=mod; ll res=0; while(b) { if(b&1) { res+=a; res%=mod; } a<<=1; if(a>=mod) a%=mod; b>>=1; } return res;}ll pow_mod(ll x,ll n,ll mod){ if(n==1) return x%mod; x%=mod; ll t=x; ll res=1; while(n) { if(n&1) res=mult_mod(res,t,mod); t=mult_mod(t,t,mod); n>>=1; } return res;}bool test(ll a,ll n,ll x,ll t){ ll res=pow_mod(a,x,n); ll last=res; for(int i=1; i<=t; i++) { res=mult_mod(res,res,n); if(res==1&&last!=1&&last!=n-1) return true; last=res; } if(res!=1) return true; return false;}bool miller_rabin(ll n){ if(n<2) return false; if(n==2) return true; if((n&1)==0) return false; ll x=n-1,t=0; while((x&1)==0) { x>>=1; t++; } for(int i=0; i
=n) p=pollard_rho(p,rand()%(n-1)+1); find_factor(p); find_factor(n/p);}int main(){ srand(time(0)); int t; scanf("%d",&t); ll n; while(t--) { scanf("%I64d",&n); if(miller_rabin(n)||n<=1) { printf("oh,no.\n"); continue; } tot=0; find_factor(n); sort(factor,factor+tot); int f=1; for(int i=1; i

 

转载于:https://www.cnblogs.com/BobHuang/p/7805731.html

你可能感兴趣的文章
Java 11.do语句
查看>>
学习理论之感知器与最大间隔分类器
查看>>
我们建了一个 Golang 硬核技术交流群(内含视频福利)
查看>>
Be Nice!要善良
查看>>
二、ansible配置简要介绍
查看>>
解决docker容器中无ifconfig命令和ping命令问题
查看>>
CHAR、TCHAR、WCHAR_T之间的区别与问题
查看>>
sql小计合计
查看>>
安装Java
查看>>
Ubuntu Linux输入法fcitx方块乱码解决设置
查看>>
node递归批量重命名指定文件夹下的文件
查看>>
python if not用法
查看>>
python-2
查看>>
选择器
查看>>
springMVC参数的获取区别
查看>>
spring事务
查看>>
node遇到的一些坑,npm无反应,cordova安装以后显示不是内部或外部命令
查看>>
[ASP.NET MVC]让Html.RenderAction支持Lamda表达式
查看>>
JDK1.8十个新特性
查看>>
mybatis使用中的记录
查看>>