这里贴个模板吧。反正是不太理解

看原题就可以理解用法!!

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
#define Times 10
typedef __int64 LL;
map<LL,int>m;
LL Random(LL n)
{
return ((double)rand()/RAND_MAX*n+0.5);
}
LL multi(LL a,LL b,LL mod)
{
LL ans=0;
while(b)
{
if(b&1)
{
b--;
ans=(ans+a)%mod;
}
else
{
b/=2;
a=(a+a)%mod;
}
}
return ans;
}
LL Pow(LL a,LL b,LL mod)
{
LL ans=1;
while(b)
{
if(b&1)
{
b--;
ans=multi(ans,a,mod);
}
else
{
b/=2;
a=multi(a,a,mod);
}
}
return ans;
}
bool witness(LL a,LL n)
{
LL d=n-1;
while(!(d&1))
d>>=1;
LL t=Pow(a,d,n);
while(d!=n-1 && t!=1 && t!=n-1)
{
t=multi(t,t,n);
d<<=1;
}
return t==n-1 || d&1;
}
bool miller_rabin(LL n)
{
if(n==2)
return true;
if(n<2||!(n&1))
return false;
for(int i=1;i<=Times;i++)
{
LL a=Random(n-2)+1;
if(!witness(a,n))
return false;
}
return true;
}
LL gcd(LL a,LL b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
LL pollard_rho(LL n,LL c)
{
LL x,y,d,i=1,k=2;
x=Random(n-1)+1;
y=x;
while(1)
{
i++;
x=(multi(x,x,n)+c)%n;
d=gcd(y-x,n);
if(1<d&&d<n)
return d;
if(y==x)
return n;
if(i==k)
{
y=x;
k<<=1;
}
}
}
void find(LL n,LL c)
{
if(n==1)
return ;
if(miller_rabin(n))
{
m[n]++;
return ;
}
LL p=n;
while(p>=n)
p=pollard_rho(p,c--);
find(p,c);
find(n/p,c);
}
int main()
{
int t;
cin>>t;
while(t--)
{
LL n;
cin>>n;
m.clear();
find(n,2013724);
if(m.size()==1)
cout<<1<<" "<<n/m.begin()->first<<endl;
else
{
LL ans=0;
map<LL,int>::iterator it=m.begin();
for(;it!=m.end();it++)
ans+=Pow(it->first,it->second,n);
cout<<m.size()<<" "<<ans<<endl;
}
}
return 0;
}

  

最新文章

  1. 关于大型网站技术演进的思考(十九)--网站静态化处理—web前端优化—上(11)
  2. Thinkphp 用PHPExcel 导入Excel
  3. 跟我一起学WCF(9)——WCF回调操作的实现
  4. tomcat的部署
  5. I.MX6 Power off register hacking
  6. Robotium 系列(2) - 简单介绍Monkey和MonkeyRunner
  7. H Language Blueprint
  8. Python初学
  9. Android Studio相关资料链接
  10. 【微信小程序项目实践总结】30分钟从陌生到熟悉
  11. 聊聊openjdk的BufferPoolMXBean
  12. Html 页面载入内容前,显示 loading 效果。
  13. mysql索引类型-方法-形式-使用时机-不足之处--注意事项
  14. window下git的下载
  15. mint19 源码安装python3.7
  16. jdk src 学习 Threadlocal
  17. IDEA初始化配置
  18. tp5---auth权限搭建2
  19. 2017 ccpc哈尔滨 A题 Palindrome
  20. 安装jdk1.8,编写环境变量

热门文章

  1. 点击查看大图Activity
  2. STL Allocator
  3. Mybatis学习系列(六)延迟加载
  4. 微信小程序小程序使用scroll-view不能使用下拉刷新的解决办法
  5. js+jquery 常用选择器函数
  6. capacilitys 持续集成
  7. IO调度
  8. 关于如何利用原生js动态给一个空对象添加属性以及属性值
  9. SSH整合主要XML代码
  10. Java IO 之 RandomAccessFile 操作文件内容