其实不过是大整数分解。。。

注意两点:注意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的更多相关文章

  1. HDU 4344 随机法判素数(费马小定理

    #include <cstdio> #include <ctime> #include <cmath> #include <algorithm> usi ...

  2. 【HDU - 4344】Mark the Rope(大整数分解)

    BUPT2017 wintertraining(15) #8E 题意 长度为n(\(n<2^{63}\))的绳子,每隔长度L(1<L<n)做一次标记,标记值就是L,L是n的约数. 每 ...

  3. HDU 4344 大数分解大素数判定

    这里贴个模板吧.反正是不太理解 看原题就可以理解用法!! #include <cstdio> #include <iostream> #include <algorith ...

  4. pollard_rho 学习总结 Miller_Rabbin 复习总结

    吐槽一下名字,泼辣的肉..OwO 我们知道分解出一个整数的所有质因子是O(sqrt(n)/ln(n))的 但是当n=10^18的时候就显得非常无力的 这个算法可以在大概O(n^(1/4))的时间复杂度 ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第0步---知识点总结&amp;效果预览&amp;设计思路

    /* 说明: **1.本次游戏实例是<cocos2d-x游戏开发之旅>上的最后一个游戏.这里用3.0重写并做下笔记 **2.我也问过木头本人啦,他说:随便写.第一别全然照搬代码:第二能够说 ...

  2. TCP三次握手及关闭时的2MSL分析

    TCP/IP三次握手四次挥手,是非常重要的,这个链接与关闭过程也是非常easy的.但为什么是三次握手?以及为什么要等待2MSL的状态?大部分人或许听到这个问题就蒙了.这篇博客就综合<TCP/IP ...

  3. c20---指向函数的指针

    // // main.c // 指向函数的指针 #include <stdio.h> void test() { printf("哥被执行了\n"); } int ge ...

  4. Android系统之Recovery移植教程 【转】

    本文转载自:http://luckytcl.blog.163.com/blog/static/14258648320130165626644/ recovery的移植,这方面的资料真实少之又少啊,谷歌 ...

  5. elasticsearch indices.recovery 流程分析(索引的_open操作也会触发recovery)——主分片recovery主要是从translog里恢复之前未写完的index,副分片recovery主要是从主分片copy segment和translog来进行恢复

    摘自:https://www.easyice.cn/archives/231 elasticsearch indices.recovery 流程分析与速度优化 目录 [隐藏] 主分片恢复流程 副本分片 ...

  6. DB2 char长度问题

    问题:发现用char转换了后的值长度都变为了11,更长的变为了254

  7. 【原创】IBM Websphere 报错:JSPG0120E: 为 pageEncoding 属性和匹配 URI 模式的配置元素指定不同的值是非法的。

    websphere中间件,在打开一个jsp页面时报: IBM Websphere 报错:JSPG0120E: 为 pageEncoding 属性和匹配 URI 模式的配置元素指定不同的值是非法的. . ...

  8. 决策树构建算法之—C4.5

    这个网站值得收藏一下,原文链接:http://shiyanjun.cn/archives/428.html 决策树算法的优越性在于:离散学习算法进行组合总可以表达任意复杂的布尔函数,并不受数据集的限制 ...

  9. 杭电2053 WA

    #include<stdio.h> int main() { ]; while(scanf("%d",&n)!=EOF) { ;i<=;i++) { a[ ...

  10. 01--Qt扫盲篇

    Qt扫盲篇 1.What is Qt 一个跨平台应用程序和UI开发框架,主要偏向于UI框架方面,由诺基亚公司开发维护. 使用 Qt 只需一次性开发应用程序,无须重新编写源代码,便可跨不同桌面和嵌入式操 ...