Eddy's research I


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6664    Accepted Submission(s): 3997

Problem Description

Eddy's interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can't write program, so Eddy has to ask intelligent you to help him, he asks you to write
a program which can do the number to divided into the multiply of prime number factor .



Input

The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.

 

Output

You have to print a line in the output for each entry with the answer to the previous question.

 

Sample Input

11

9412

 

Sample Output

11

2*2*13*181

 

Author

eddy

题目大意:随意一个数x,都能够被分解为几个素数(能够同样)相乘的形式。如今给你一个数x,

把它分解为几个素数相乘的形式。

思路:这里x的规模最大为65535。所以用简单的素性推断方法直接暴力也能够过。网上贴的

代码大多简单,这里贴一个用【Miller Rabin素数測试】+【Pollar Rho整数分解】来做的代码

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define MAX_VAL (pow(2.0,60))
//miller_rabbin素性測试
__int64 mod_mul(__int64 x,__int64 y,__int64 mo)
{
__int64 t,T,a,b,c,d,e,f,g,h,v,ans;
T = (__int64)(sqrt(double(mo)+0.5)); t = T*T - mo;
a = x / T;
b = x % T;
c = y / T;
d = y % T;
e = a*c / T;
f = a*c % T;
v = ((a*d+b*c)%mo + e*t) % mo;
g = v / T;
h = v % T;
ans = (((f+g)*t%mo + b*d)% mo + h*T)%mo;
while(ans < 0)
ans += mo;
return ans;
} __int64 mod_exp(__int64 num,__int64 t,__int64 mo)
{
__int64 ret = 1, temp = num % mo;
for(; t; t >>=1,temp=mod_mul(temp,temp,mo))
if(t & 1)
ret = mod_mul(ret,temp,mo); return ret;
} bool miller_rabbin(__int64 n)
{
if(n == 2)
return true;
if(n < 2 || !(n&1))
return false;
int t = 0;
__int64 a,x,y,u = n-1;
while((u & 1) == 0)
{
t++;
u >>= 1;
}
for(int i = 0; i < 50; i++)
{
a = rand() % (n-1)+1;
x = mod_exp(a,u,n);
for(int j = 0; j < t; j++)
{
y = mod_mul(x,x,n);
if(y == 1 && x != 1 && x != n-1)
return false;
x = y;
}
if(x != 1)
return false;
}
return true;
}
//PollarRho大整数因子分解
__int64 minFactor;
__int64 gcd(__int64 a,__int64 b)
{
if(b == 0)
return a;
return gcd(b, a % b);
} __int64 PollarRho(__int64 n, int c)
{
int i = 1;
srand(time(NULL));
__int64 x = rand() % n;
__int64 y = x;
int k = 2;
while(true)
{
i++;
x = (mod_exp(x,2,n) + c) % n;
__int64 d = gcd(y-x,n);
if(1 < d && d < n)
return d;
if(y == x)
return n;
if(i == k)
{
y = x;
k *= 2;
}
}
}
__int64 ans[1100],cnt;
void getSmallest(__int64 n, int c)
{
if(n == 1)
return;
if(miller_rabbin(n))
{
ans[cnt++] = n;
return;
}
__int64 val = n;
while(val == n)
val = PollarRho(n,c--);
getSmallest(val,c);
getSmallest(n/val,c);
} int main()
{
__int64 X;
while(~scanf("%I64d",&X))
{
cnt = 0;
getSmallest(X,200);
sort(ans, ans+cnt);
for(int i = 0; i < cnt; i++)
{
if(i!=0)
printf("*%I64d",ans[i]);
else
printf("%I64d",ans[i]);
}
printf("\n");
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

HDU1164_Eddy&#39;s research I【Miller Rabin素数测试】【Pollar Rho整数分解】的更多相关文章

  1. POJ1811_Prime Test【Miller Rabin素数测试】【Pollar Rho整数分解】

    Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 29193 Accepted: 7392 Case Time ...

  2. POJ2429_GCD &amp; LCM Inverse【Miller Rabin素数測试】【Pollar Rho整数分解】

    GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9756Accepted: 1819 ...

  3. POJ1811_Prime Test【Miller Rabin素数測试】【Pollar Rho整数分解】

    Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 29193 Accepted: 7392 Case Time ...

  4. Miller Rabin素数检测与Pollard Rho算法

    一些前置知识可以看一下我的联赛前数学知识 如何判断一个数是否为质数 方法一:试除法 扫描\(2\sim \sqrt{n}\)之间的所有整数,依次检查它们能否整除\(n\),若都不能整除,则\(n\)是 ...

  5. Miller Rabin素数检测

    #include<iostream> #include<cstdio> #include<queue> #include<cstring> #inclu ...

  6. HDU 3864 D_num Miller Rabin 质数推断+Pollard Rho大整数分解

    链接:http://acm.hdu.edu.cn/showproblem.php? pid=3864 题意:给出一个数N(1<=N<10^18).假设N仅仅有四个约数.就输出除1外的三个约 ...

  7. Miller Rabbin素数测试

    步骤 ①先写快速幂取模函数 ②MR算法开始 (1)传入两个参数一个是底数一个是n也就是幂数,如果n是一个合数那么可以判定,这个数一定不是素数 (2)然后开始寻找一个奇数的n去计算,如果最后满足a^d% ...

  8. 关于素数:求不超过n的素数,素数的判定(Miller Rabin 测试)

    关于素数的基本介绍请参考百度百科here和维基百科here的介绍 首先介绍几条关于素数的基本定理: 定理1:如果n不是素数,则n至少有一个( 1, sqrt(n) ]范围内的的因子 定理2:如果n不是 ...

  9. POJ1811- Prime Test(Miller–Rabin+Pollard's rho)

    题目大意 给你一个非常大的整数,判断它是不是素数,如果不是则输出它的最小的因子 题解 看了一整天<初等数论及其应用>相关部分,终于把Miller–Rabin和Pollard's rho这两 ...

随机推荐

  1. C语言深度剖析-----多维数组和多维指针

    多维数组和多维指针 指向指针的指针 指针变量同样也有传址调用和传值调用 case1:估算要5个字节的空间,实际只用前面3个字节,设计释放空的2字节 case2:扩充到10字节 二维数组与二维指针 二维 ...

  2. swift开发网络篇—利用NSURLSession 发送GET和POST请求

    说明:本文示例代码发送的请求均为http请求,需要对info.plist文件进行配置.如何配置,请参考https://github.com/HanGangAndHanMeimei/iOS9Adapta ...

  3. 4、linux开发中常用指令

    1.cat /proc/device 可以查看各个全部字符设备和块设备,在register_chrdev中设置的名字在打印出来的信息中可以看到:2.top 可以看各个应用程序占用CPU量及PID等信息 ...

  4. Jquery浅克隆与深克隆是什么

    Jquery浅克隆与深克隆是什么 一.总结 一句话总结:克隆的那些标签内容就是对应元素的html,事件就是那些绑定的事件. 1.jquery克隆的时候的注意事项是什么? 元素数据(data)内对象和数 ...

  5. MHA 一主两从搭建-脚本VIP-自动切换

    环境介绍:主机名 IP MHA角色 MySQL角色node1 192.168.56.26 Node MySQL Master node2 192.168.56.27 Node MySQL Master ...

  6. [D3] Convert Dates to Numeric Values with Time Scales in D3 v4

    Mapping abstract values to visual representations is what data visualization is all about, and that’ ...

  7. 【u211】编码

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 假设phi(W)得到是按照以下算法编码后的结果: 1. 如果W的长度为1那么phi(W)即为W: 2. ...

  8. Error while trying to retrieve text for error ORA-12705

    今天, 按照以前的学习笔记, 配置ProC 但是, 却发生了如题的错误. Google一下, 都是NLS_LANG环境变量设置有问题, 我核一下没有问题. 问题在哪? 原来是ORACLE_HOME环境 ...

  9. [GraphQL] Use GraphQLList with GraphQLObject Types

    When working with collections of things in GraphQL, we'll always reach out for the GraphQLListType. ...

  10. iOS writeTofile 和对象的序列化

    前言:做了一个图片浏览的小demo,支持随意添加.删除图片,图片放大.缩小,带矩形框的截图.随后几篇博客都会详细讲解在此过程中遇到的各种问题.这篇主要讲,在做添加.删除这个功能时,遇到的存文件的问题. ...