题意:给你一个个数对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. 记一次IDEA编译器调优

    前言: 我们知道,IDEA是用Java写的,那么他肯定也存在虚拟机的调优的问题,那么今天我们就对它进行开刀. 下面是默认参数 位置在:C:\Program Files\JetBrains\Intell ...

  2. 自定义Fiddler插件一

    上个月自定义了一个Fiddler的插件,可以根据请求生成接口自动化测试的RF和Python代码,这样测试人员只需要手动操作页面用Fiddler抓取报文,就可以直接生成RF.Python代码,然后只需要 ...

  3. AutoIt介绍

    AutoIt的下载网址: https://www.autoitscript.com/site/autoit/downloads/ AutoIt在线文档:http://www.autoit3.cn/Do ...

  4. C# 常用的加密代码参考

    1.MD5加密 public static string EncryptString(string source) { string result; if (source == string.Empt ...

  5. C# 位运算详解

    运算符 描述 &(位与) 当两个二进制操作位都为1时,结果就为1 |(位或) 当两个二进制操作位有1个为1时,结果就为1 ^(位异或) 当两个二进制操作位只有1个为1时,结果为1 ~(位非) ...

  6. ip2Long 代码

    def ip2Long(ip: String): Long = { val fragments = ip.split("[.]") var ipNum = 0L for (i &l ...

  7. Matlab 如何输入矩阵

    A=[1 2 3;4 5 6;7 8 9],每行之间用分号隔开 也可以用循环控制输入 n=input('请输入矩阵阶数:') for i=1:n     for j=1:n         a(i,j ...

  8. 浅析"WeixinJSBridge is not defined"

    Fundebug并没有使用微信 JS-SDK,然而却收到了WeixinJSBridge is not defined的报错: 我们的用户也收到了类似的错误报警,并且很多开发者都遇到类似的问题: 我的微 ...

  9. blfs(systemd版本)学习笔记-配置远程访问和管理lfs系统

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 要实现远程管理和配置lfs系统需要配置以下软件包: 前几页章节脚本的配置:https://www.cnblogs.com/ren ...

  10. [Error] 未发现相关 less 编译器配置,请检查wepy.config.js文件

    此错误是由于缺少包引起的 npm install less -d 直接装包即可