1059 Prime Factors (25分)
 

Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p​1​​​k​1​​​​×p​2​​​k​2​​​​×⋯×p​m​​​k​m​​​​.

Input Specification:

Each input file contains one test case which gives a positive integer N in the range of long int.

Output Specification:

Factor N in the format N = p​1​​^k​1​​*p​2​​^k​2​​**p​m​​^k​m​​, where p​i​​'s are prime factors of N in increasing order, and the exponent k​i​​ is the number of p​i​​ -- hence when there is only one p​i​​, k​i​​ is 1 and must NOT be printed out.

Sample Input:

97532468

Sample Output:

97532468=2^2*11*17*101*1291
思路:算术基本定理(唯一分解定理)
用从小到大的素数整除n,vector保留素数及其对应的指数
 #include <iostream>
#include <vector>
#include <algorithm> using namespace std ; typedef pair<int,int> PII ;
vector<PII> vc ;
int n ; void get(){
for(int i=;i<=n/i;i++){
if(n%i==){
int s = ;
while(n%i==){
s++ ;
n /= i ;
}
vc.push_back({i,s}) ;
}
}
if(n>){
vc.push_back({n,}) ;
}
} int main(){
cin >> n ; if(n==){
printf("1=1") ;
}else{
printf("%d=",n) ;
get() ;
int la = vc.size() ;
for(int i=;i<la;i++){
if(i){
printf("*") ;
}
printf("%d",vc[i].first) ;
if(vc[i].second>){
printf("^%d",vc[i].second) ;
}
}
} return ;
}
 

PAT1059Prime Factors的更多相关文章

  1. [CareerCup] 7.7 The Number with Only Prime Factors 只有质数因子的数字

    7.7 Design an algorithm to find the kth number such that the only prime factors are 3,5, and 7. 这道题跟 ...

  2. 1096. Consecutive Factors (20)

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  3. 机器学习 —— 概率图模型(Homework: Factors)

    Talk is cheap, I show you the code 第一章的作业主要是关于PGM的因子操作.实际上,因子是整个概率图的核心.对于有向图而言,因子对应的是CPD(条件分布):对无向图而 ...

  4. ACM - ICPC World Finals 2013 D Factors

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 一个最基本的算数法则就是大于1的整数 ...

  5. 1059. Prime Factors (25)

    时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...

  6. [Machine Learning] Probabilistic Graphical Models:一、Introduction and Overview(2、Factors)

    一.什么是factors? 类似于function,将一个自变量空间投影到新空间.这个自变量空间叫做scope. 二.例子 如概率论中的联合分布,就是将不同变量值的组合映射到一个概率,概率和为1. 三 ...

  7. Project Euler:Problem 47 Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2 × 7 15 = 3 × 5 The ...

  8. PAT 1059. Prime Factors (25) 质因子分解

    题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...

  9. (Problem 47)Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2  7 15 = 3  5 The fi ...

随机推荐

  1. TZOJ5697: 数据结构实验:归并排序

    #include<stdio.h> #include<stdlib.h> void merge(int a[], int start,int mid,int end) { )) ...

  2. hyper-v安装windows7

    win7镜像下载地址 http://msdn.itellyou.cn/ 该网站都是微软系列的正规软件 非常好用 在hyper-v 虚拟机安装windows系统时,到百度搜索了几个iso 都不好用 到h ...

  3. UI测试用例设计,场景测试法

    百度一番,没有发现详细的UI测试用例设计方法,只能自己整理一下,学习.改进. 那么正题来了,我们慢慢缕下思路: 1.整理要测实体中的,处理逻辑.触发规则.动作. 2.将场景测试抽象出来 3.到这个时候 ...

  4. 如何更精准地设置 C# / .NET Core 项目的输出路径?(包括添加和删除各种前后缀)

    原文:如何更精准地设置 C# / .NET Core 项目的输出路径?(包括添加和删除各种前后缀) 我们都知道可以通过在 Visual Studio 中设置输出路径(OutputPath)来更改项目输 ...

  5. java之hibernate之单向的多对多关联映射

    这篇 单向的多对多关联映射 1.如何在权限管理中,角色和权限之间的关系就是多对多的关系,表结构为: 2.类结构 Permission.java public class Permission impl ...

  6. postman 测试Api接口注意事项

    1.简单数据传输 2.对象传输 使用的是post方式请求 在Headers设置: 在Body写入对象信息,主要红线的地方:1.raw选中 2.j'son格式 form表单提交数据测试 在header里 ...

  7. CarbonCopyCloner 硬盘对拷

    CarbonCopyCloner 硬盘对拷 建议使用 5.1.14-b1以上的版本. 安装文件包 CarbonCopyCloner-5.1.14-b1.dmg ================== E ...

  8. JavaScript的深浅复制

    JavaScript的深浅复制 为什么有深复制.浅复制? JavaScript中有两种数据类型,基本数据类型如undefined.null.boolean.number.string,另一类是Obje ...

  9. Selenium文件上传

    转自:https://www.cnblogs.com/miaojjblog/p/9679915.html Web上本地上传图片,弹出的框Selenium是无法识别的,也就是说,selenium本身没有 ...

  10. 蓝牙 BLE 三种 UUID 格式转换

    蓝牙广播中对服务 UUID 格式定义都有三种 16 bit UUID.32 bit UUID.128 bit UUID. 但是熟悉安卓开发的小伙伴都知道接口都 UUID 格式,fromString 时 ...