题意:给你一个个数对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. MapReduce核心 - - - Shuffle

    大数据名词(1) -Shuffle     Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解MapReduce, Shuffle是必须要了解的.我看过很多相关的资料,但每 ...

  2. c#方法转异步例子

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. [PHP] 算法-二位有序数组中查找的PHP实现

    在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 1.二 ...

  4. jQuery文档操作方法对比和src写法

    jQuery文档操作方法对比 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  5. 【Tomcat】Tomcat日志切割

    下载并解压缩 cronolog # tar zxvf cronolog-1.6.2.tar.gz 2.进入cronolog安装文件所在目录 # cd cronolog-1.6.2 3.运行安装  # ...

  6. Java中变量之局部变量、本类成员变量、父类成员变量的访问方法

    变量:局部变量.本类成员变量.父类成员变量 如何访问:如果变量名相同,则采用就近原则,哪个变量离所要调用的访问最近,那就么就输出,优先顺序为:局部变量 > 本类成员变量 > 父类成员变量 ...

  7. 使用Via浏览器+ADM下载器突破百度网盘下载限速

    1.下载必要工具 via浏览器 ADM下载器 2.自定义 UA UA 是一串特殊字符,用来告诉所访问的网站,手机使用的操作系统及版本.CPU 类型.浏览器及版本等信息.UA 内容如下: Mozilla ...

  8. Vue学习资料

    1. {{ msg }}插值表达式. v-text:将数据插入到页面中,没有闪烁问题. v-cloak:通过style属性选择器的方式display:none:防止闪烁问题. v-html:将标签解析 ...

  9. css中那些属性可以被继承

    主要的有: 字体相关:line-height, font-family, font-size, font-style, font-variant, font-weight, font 文本相关: le ...

  10. 安全测试 web应用安全测试之XXS跨站脚本攻击检测

    web应用安全测试之XXS跨站脚本攻击检测 by:授客 QQ:1033553122 说明 意在对XSS跨站脚本攻击做的简单介绍,让大家对xss攻击有个初步认识,并能够在实际工作当中运用本文所述知识做些 ...