唯一分解定理 poj 1365
一行代表一个数 x 给你底数和指数
求x-1的唯一分解定理的底数和指数 从大到小输出
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h> using namespace std;
#define MAXN 100010
double z[MAXN],x[MAXN];
bool pri[MAXN];
int p[MAXN];
int di[MAXN],zhi[MAXN]; int main()
{
memset(pri,,sizeof(pri)); for(int i=;i<=;i++)
{
if(!pri[i])
for(int j=i*i;j<=;j=j+i)
pri[j]=;
}
int ans=;
for(int i=;i<=;i++)
if(!pri[i])
p[ans++]=i; while(scanf("%lf",&z[])!=EOF)
{
if(z[]==)
break;
char s;
scanf("%lf%c",&x[],&s);
int cnt=;
int cnt1=;
memset(di,,sizeof(di));
memset(zhi,,sizeof(zhi)); if(s=='\n')
{
double a=pow(z[],x[]);
long long b=(long long) a;
b--; for(int i=;i<ans;i++)
{
if(b%p[i]==)
{
while(b%p[i]==)
{
b=b/p[i];
zhi[cnt1]++;
}
di[cnt1++]=p[i];
}
}
if(b>)
{
di[cnt1]=b;
zhi[cnt1++]=;
}
for(int i=cnt1-;i>;i--)
printf("%d %d ",di[i],zhi[i]);
printf("%d %d\n",di[],zhi[]);
}
else
{
double a=pow(z[],x[]);
while(scanf("%lf%lf%c",&z[cnt],&x[cnt],&s))
{
cnt++;
if(s=='\n')
break;
}
for(int i=;i<cnt;i++)
{
a*=pow(z[i],x[i]);
}
long long b=(long long) a;
b--;
for(int i=;i<ans;i++)
{
if(b%p[i]==)
{
while(b%p[i]==)
{
b=b/p[i];
zhi[cnt1]++;
}
di[cnt1++]=p[i];
}
}
if(b>)
{
di[cnt1]=b;
zhi[cnt1++]=;
}
for(int i=cnt1-;i>;i--)
printf("%d %d ",di[i],zhi[i]);
printf("%d %d\n",di[],zhi[]);
} }
return ;
}
唯一分解定理 poj 1365的更多相关文章
- POJ 1730 Perfect Pth Powers(唯一分解定理)
http://poj.org/problem?id=1730 题意:给出一个n,a=b^p,求出最大p值. 思路: 首先利用唯一分解定理,把n写成若干个素数相乘的形势.接下来对于每个指数求最大公约数, ...
- POJ 1845-Sumdiv(快速幂取模+整数唯一分解定理+约数和公式+同余模公式)
Sumdiv Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- POJ - 1845 G - Sumdiv (唯一分解定理)
Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S m ...
- POJ 1845 Sumdiv (整数唯一分解定理)
题目链接 Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 25841 Accepted: 6382 Desc ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- poj2773 —— 二分 + 容斥原理 + 唯一分解定理
题目链接:http://poj.org/problem?id=2773 Happy 2006 Time Limit: 3000MS Memory Limit: 65536K Total Submi ...
- NOIP2009Hankson 的趣味题[唯一分解定理|暴力]
题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现 在,刚刚放学回家的 Hankson 正在思考一个有趣的问题. 今天在课堂上,老师讲 ...
- uva10375 Choose and Divide(唯一分解定理)
uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...
随机推荐
- NOIP2000进制转换
题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1*10^2+2*10^1+3*10^ ...
- eclipse大括号高亮显示---颜色很淡,改为显眼的颜色
window -> preferences -> java(or c++)-> editor -> matching brackets highight, color改为红色
- HTML-学习笔记(文本格式化,引用,计算机代码)
HTML 可定义很多供格式化输出的元素,比如粗体和斜体字. <b>定义粗体字体 <p>这是一段<b>粗体字体</b>通过标签定义</p> & ...
- Location 对象
Location 对象 Location 对象包含有关当前 URL 的信息. Location 对象是 window 对象的一部分,可通过 window.Location 属性对其进行访问. 注意: ...
- .Net Core 控制台程序错误:Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'.
.Net Core 控制台程序错误:Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible wi ...
- php碎片
1.flock LOCK_EX 独占锁定 LOCK_SH 共享锁定 LOCK_UN 解除锁定 LOCK_NB 锁定但不堵塞进程,直接返回false 2. fseek SEEK_CUR SEEK_END ...
- Castle IOC容器与Spring.NET配置之比较
我本人对于Spring.NET并不了解,本文只是通过一个简单的例子来比较一下两者配置之间的区别.在Castle IOC容器中,提出了自动装配(Auto-Wiring)的概念,即由容器自动管理组件之间的 ...
- mongodb分布式查询
分布式查询:mongodb的分布式模型分为replica set和sharded cluster. sharded集群中将read根据sharding key(分片键)转发到指定的shard节点,re ...
- CSS3 3D骰子
z zz zz zzzz zzzzz zzzzzz
- nfs 三个参数权限
遇到nfs客户端不可写的情况. 有延迟啊啊啊.. 等1min左右就可以写了. 挂载参数: cat /var/lib/nfs/etab -->server cat /proc/mounts ...