HDU 4344
其实不过是大整数分解。。。
注意两点:注意L 不能==N
但是,N却可以是素数。。。囧
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdio>
#define LL __int64
#define MAX 1LL<<61
#define Times 8
#define N 501
#define C 101
using namespace std;
LL cop[N];
int ct; bool cmp(LL a,LL b){
if(a<b) return true;
return false;
} LL gcd(LL a,LL b){
return b==0?a:gcd(b,a%b);
} LL random(LL n){
return (LL)((double)rand()/RAND_MAX*n+0.5);
} LL multi(LL a,LL b,LL m){ //a*b%m
LL ret=0;
while(b){
if(b&1)
ret=(ret+a)%m;
b>>=1;
a=(a<<1)%m;
}
return ret;
} LL quick(LL a,LL b,LL m){
LL ans=1;
a%=m;
while(b){
if(b&1){
ans=multi(ans,a,m);
b--;
}
b/=2;
a=multi(a,a,m);
}
return ans;
} bool Witness(LL a,LL n){
LL m=n-1;
int j=0;
while(!(m&1)){
j++;
m>>=1;
}
LL x=quick(a,m,n);
if(x==1||x==n-1)
return false;
while(j--){
x=multi(x,x,n);
if(x==n-1)
return false;
}
return true;
} bool Miller_Rabin(LL n){
if(n<2) return false;
if(n==2) return true;
if(!(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 Pollard_Rho(LL n,int c){
LL x,y,d,i=1,k=2;
x=random(n-1)+1;
y=x;
while(true){
i++;
x=(multi(x,x,n)+c)%n;
d=gcd(y-x,n);
if(d>1&&d<n){
return d;
}
if(y==x) return n;
if(i==k){
y=x;
k=k<<1;
}
}
} void find(LL n,int k){
if(n==1) return ;
if(Miller_Rabin(n)){
cop[++ct]=n;
return ;
}
LL p=n;
while(p>=n)
p=Pollard_Rho(p,k--);
find(p,k);
find(n/p,k);
} int main(){
int T;
LL n;
scanf("%d",&T);
while(T--){
scanf("%I64d",&n);
ct=0;
find(n,C);
sort(cop+1,cop+1+ct,cmp);
if(ct==1){
printf("1 1\n");
continue;
}
LL cnt=0;LL tmp=0; LL ans=0;
cop[0]=1;
cop[++ct]=1;
for(int i=1;i<=ct;i++){
if(cop[i]!=cop[i-1]){
ans+=tmp;
tmp=cop[i];
cnt++;
}
else{
tmp*=cop[i];
}
}
if(ans==n)
ans/=cop[1];
printf("%I64d %I64d\n",cnt-1,ans);
}
return 0;
}
HDU 4344的更多相关文章
- HDU 4344 随机法判素数(费马小定理
#include <cstdio> #include <ctime> #include <cmath> #include <algorithm> usi ...
- 【HDU - 4344】Mark the Rope(大整数分解)
BUPT2017 wintertraining(15) #8E 题意 长度为n(\(n<2^{63}\))的绳子,每隔长度L(1<L<n)做一次标记,标记值就是L,L是n的约数. 每 ...
- HDU 4344 大数分解大素数判定
这里贴个模板吧.反正是不太理解 看原题就可以理解用法!! #include <cstdio> #include <iostream> #include <algorith ...
- pollard_rho 学习总结 Miller_Rabbin 复习总结
吐槽一下名字,泼辣的肉..OwO 我们知道分解出一个整数的所有质因子是O(sqrt(n)/ln(n))的 但是当n=10^18的时候就显得非常无力的 这个算法可以在大概O(n^(1/4))的时间复杂度 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- hdu 1698 Just a Hook 基本线段树
使用线段树更新每段区间的奖(1,2,3),最后在统计整段区间的数和,基本线段树,果断1A啊 #include<iostream> #include<stdio.h> using ...
- hdoj--3339--In Action(最短路+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- [ASPX] DotLiquid-Asp.net模板引擎
以前用过一段时间的PHP,感觉非常不错,其中最让我难忘的就是Smarty模板引擎,当时就微微地想Asp.net里有没有像这样的模板引擎呢?不过由于之后的工作内容都用不到,或者说没有想到用模板,这想法也 ...
- javascript设计模式-掺元类
有一种重用代码的方法不需要用到严格的继承.如果想把一个函数用到多个类中,可以通过扩充的方式让这些类共享该函数.其实际做法大大体为:先创建一个包含各种通用方法的类,然后再用它扩充其他的类.这种方式就叫做 ...
- Ubuntu搭建docker环境
一丶自己搭建Ubuntu的虚拟机(网上很多教程) PS:下带图形化界面的Ubuntu镜像,这里只说一下要装那些工具和做那些配置 安装vim sudo apt-get install ...
- Mysql数据类型(二)
字符类型 #官网:https://dev.mysql.com/doc/refman/5.7/en/char.html #注意:char和varchar括号内的参数指的都是字符的长度 #char类型:定 ...
- CI中的文件上传
//首先在控制器中装载url类和view视图: //在view视图中创建一个表单,注:在做文件上传一定要写encype=“multipart/form-data”: //form表单的提交页面应该使用 ...
- 如何用npm安装vue
下载安装node.js,安装完毕做好配置后开始运行. 如果npm版本太低,需要升级一下npm # 查看版本 $ npm -v #升级 npm cnpm install npm -g 安装vue-cli ...
- 利用chrome浏览器断电调试确定函数触发的位置
比如某天遇到这样一个问题,页面有一个按钮,上面绑定了事件可能是多个事件,然后我们点击后出现了bug,我们要如何快速定位到这个事件,如果页面只有一个js或少量的js,我们一个打开查找,也可以接受.但是如 ...
- mysql 锁表查看
information_schema.INNODB_TRX 一般锁表后查询这个表 把相关的事务执行线程kill就可以了,可以分析sql语句执行场景 INNODB_LOCKS PROCES ...