题意:给你一个个数对a, b 表示ab这样的每个数相乘的一个数n,求n-1的质数因子并且每个指数因子k所对应的次数 h.

先把合数分解模板乖乖放上:

for (int i = ; ans != ; ++i)
{
if (ans%i == )
{
num[cnt] = i; int k = ;
while (ans%i == ){ ++k; ans /= i; }
index[cnt++] = k;
}
if (i > )break;
}
if (ans != ){ num[cnt] = ans; index[cnt++] = ; }

然后,我自己写了个快速幂

快速幂的模板:

ll pow(ll a, ll n)
{
ll res;
for (res = ; n;a=a*a, n>>=)
if (n & ) res = res*a;
return res;
}

AC代码:

#include<cstdio>
#include<cstring>
#define ll long long
int num[];
int index[];
ll pow(ll a, ll n)
{
ll res;
for (res = ; n;a=a*a, n>>=)
if (n & ) res = res*a;
return res;
}
int main()
{
while (){
ll a, b, ans = ;
while (scanf("%lld", &a), a!=){
scanf("%lld", &b);
ans *= pow(a, b);
char nn=getchar();
if (nn == '\n')break;
}
if (a == )break;
ans--;
int cnt = ;
for (int i = ; ans != ; ++i)
{
if (ans%i == )
{
num[cnt] = i; int k = ;
while (ans%i == ){ ++k; ans /= i; }
index[cnt++] = k;
}
if (i > )break;
}
if (ans != ){ num[cnt] = ans; index[cnt++] = ; }
for (int i = cnt-; i >= ; --i)
printf("%d %d%c", num[i], index[i], " \n"[i == ]);
}
}

pku1365 Prime Land (数论,合数分解模板)的更多相关文章

  1. POJ1365 - Prime Land(质因数分解)

    题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...

  2. POJ1365 Prime Land【质因数分解】【素数】【水题】

    题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特 ...

  3. HDU 4610 Cards (合数分解,枚举)

    Cards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  4. POJ 1365 Prime Land(数论)

    题目链接: 传送门 Prime Land Time Limit: 1000MS     Memory Limit: 10000K Description Everybody in the Prime ...

  5. [暑假集训--数论]poj1365 Prime Land

    Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...

  6. 数学--数论--POJ1365——Prime Land

    Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...

  7. [POJ 1365] Prime Land

    Prime Land Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3211   Accepted: 1473 Descri ...

  8. Perfect Pth Powers pku-1730(筛+合数分解)

    题意:x可以表示为bp, 求这个p的最大值,比如 25=52, 64=26,  然后输入x 输出 p 就是一个质因子分解.算法.(表示数据上卡了2个小时.) 合数质因子分解模板. ]; ]; ; ;n ...

  9. hdu_4497GCD and LCM(合数分解)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 GCD and LCM Time Limit: 2000/1000 MS (Java/Other ...

随机推荐

  1. Scala面向对象编程与类型系统

    Scala支持面向对象编程, 其面向对象特性与Java有共同之处并添加了很多新的特性. 类定义 scala使用class关键字定义类: class MyComplex(real0:Double, im ...

  2. SQL SERVER 如何判断是不是年,月最后一天

    , SYSDATETIME())) PRINT '不是'; ELSE PRINT '是'; GO , SYSDATETIME())) PRINT '不是'; ELSE PRINT '是'; GO 1. ...

  3. Intellij Idea乱码解决方案

    使用Intellij Idea经常遇到的三种乱码问题: 1.工程代码乱码 2.main方法运行,控制台乱码 3.tomcat运行,控制台乱码 解决方案: 1.工程代码乱码 Settings > ...

  4. MAC下搭建个人博客

    安装homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/inst ...

  5. JavaScript中的window对象的属性和方法;JavaScript中如何选取文档元素

    一.window对象的属性和方法 ①setTimeout()方法用来实现一个函数在指定毫秒之后运行,该方法返回一个值,这个值可以传递给clearTimeout()用于取消这个函数的执行. ②setIn ...

  6. js 中导出excel 较长数字串会变成科学计数法

    在做项目中,碰到如题的问题.比如要将居民的信息导出到excel中,居民的身份证号码因为长度过长(大于10位),excel会自动的将过长的数字串转换成 科学计数法.现在网上找到解决方案之一: (在数字串 ...

  7. layui 图片上传+表单提交+ Spring MVC

    Layui 的上传是最常用的, 不可或缺, 记录一下代码, 以后复制都能用!! 1.前端HTML: <div class="layui-form-item"> < ...

  8. Python3选择支持非ASCII码标识符的缘由

    原文在: PEP 3131 -- Supporting Non-ASCII Identifiers. Python2并不支持非ASCII码标识符. PEP的全称是Python Enhancement ...

  9. 可视化接口管理工具RAP,模拟数据,校验接口

    最近看到一个不错的接口管理的工具,分享一下 RAP ppt介绍:http://www.imooc.com/video/11060 RAP是一个可视化接口管理工具 通过分析接口结构,动态生成模拟数据,校 ...

  10. Android Studio 在项目中引用第三方jar包

    在Android Studio项目中引用第三方jar包的方法: 步骤: 1.在build.gradle文件中添加如下代码: 备注:要添加在Android作用域下 sourceSets { main { ...