pku1365 Prime Land (数论,合数分解模板)
题意:给你一个个数对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 (数论,合数分解模板)的更多相关文章
- POJ1365 - Prime Land(质因数分解)
题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...
- POJ1365 Prime Land【质因数分解】【素数】【水题】
题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特 ...
- HDU 4610 Cards (合数分解,枚举)
Cards Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- POJ 1365 Prime Land(数论)
题目链接: 传送门 Prime Land Time Limit: 1000MS Memory Limit: 10000K Description Everybody in the Prime ...
- [暑假集训--数论]poj1365 Prime Land
Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...
- 数学--数论--POJ1365——Prime Land
Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...
- [POJ 1365] Prime Land
Prime Land Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3211 Accepted: 1473 Descri ...
- Perfect Pth Powers pku-1730(筛+合数分解)
题意:x可以表示为bp, 求这个p的最大值,比如 25=52, 64=26, 然后输入x 输出 p 就是一个质因子分解.算法.(表示数据上卡了2个小时.) 合数质因子分解模板. ]; ]; ; ;n ...
- hdu_4497GCD and LCM(合数分解)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 GCD and LCM Time Limit: 2000/1000 MS (Java/Other ...
随机推荐
- 探秘 Java 热部署
# 前言 在之前的 深入浅出 JVM ClassLoader 一文中,我们说可以通过修改默认的类加载器实现热部署,但在 Java 开发领域,热部署一直是一个难以解决的问题,目前的 Java 虚拟机只能 ...
- C# ListBox 自动滚动到底部 方法:
在ListBox中添加一条记录(ListBox.Items.Add方法)后,滚动条会自动回到顶部.我们可能更希望它自动滚动到底部,简要介绍几种方法. 方法一: this.listBox1.Items. ...
- Bootstrap学习记录-3.Badge、Breadcrumb、Buttons、 Button Group、Card、Carousel
1. Badge Badge作为数值标记组件,它能作为链接或按钮的一部分来提供计数作用,而且它通过使用相对字体大小来适应父级元素的大小.它的最基本的修饰符为.badge .badge-*. <b ...
- mysql百万的数据快速创建索引
测试数据本机一张表users有100百万条记录.在创建此表前没有未相应字段添加索引,所以此时需要为表添加索引.但是因为数据量大的原因,索引添加可能不成功,想了很多办法,终于挖坑成功. 开始准备工作, ...
- Java框架之Struts2(三)
一.几种国际化输出方式 国际化:国际化的本质,就是查找,替换.程序界面上输出的是国际化消息的 key 所对应的值.Struts2 中的国际化机制,会根据 key 到资源文件中找对应的文本来替换上面的k ...
- Python全栈学习_day003作业
day3作业及默写 1,有变量name = "aleX leNb" 完成如下操作: 1) 移除 name 变量对应的值两边的空格,并输出处理结果 print(name.strip( ...
- canvas-tangram.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- addEventListener.js
document.addEventListener("click",function(){ console.log("添加事件监听") }) 举个例子 : 点击 ...
- 10个最佳 Javascript+HTML5 演示文稿框架
JavaScript 与 HTML5 框架在创建基于现代浏览器的演示文稿时发挥了重要作用.他们把展示插入网页,为演示信息提供了一个有效方式.一般来说,手工插入花费大量事件和精力,它很复杂,以至于新手们 ...
- http2
原文转至:https://zhuanlan.zhihu.com/p/26559480 HTTP/2 是 HTTP 协议自 1999 年 HTTP 1.1 发布后的首个更新,主要基于 SPDY 协议.由 ...