Source:

PAT A1059 Prime Factors (25 分)

Description:

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

Keys:

  • 模拟题

Attention:

  • 注意N==1的情况

Code:

 /*
Data: 2019-07-08 20:14:37
Problem: PAT_A1059#Prime Factors
AC: 14:40 题目大意:
打印正整数N的质因子,及其个数
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
struct node
{
LL p,k;
}; int main()
{
LL n;
vector<node> fac;
scanf("%lld", &n);
printf("%lld=", n);
for(LL i=; i<=(LL)sqrt(1.0*n); i++)
{
if(n%i == )
{
node t = node{i,};
while(n%i== && n!=)
{
t.k++;
n /= i;
}
fac.push_back(t);
}
if(n == )
break;
}
if(n != )
fac.push_back(node{n,});
if(fac.size()==)
printf("");
for(int i=; i<fac.size(); i++)
{
printf("%lld", fac[i].p);
if(fac[i].k != )
printf("^%lld", fac[i].k);
printf("%c", i==fac.size()-?'\n':'*');
} return ;
}

PAT_A1059#Prime 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. 1059. Prime Factors (25)

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

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

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

  4. 2014辽宁ACM省赛 Prime Factors

    问题 L: Prime Factors 时间限制: 1 Sec  内存限制: 128 MB [提交][状态][论坛] 题目描写叙述 I'll give you a number , please te ...

  5. PAT1059:Prime Factors

    1059. Prime Factors (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

  6. A1059. Prime Factors

    Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...

  7. PAT 甲级 1059 Prime Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...

  8. PAT 1059 Prime Factors[难]

    1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...

  9. pat1059. Prime Factors (25)

    1059. Prime Factors (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

随机推荐

  1. webpack构建缓存机制-hash介绍

    前言 浏览器为了优化体验,会有缓存机制.如果浏览器判断当前资源没有更新,就不会去服务端下载,而是直接使用本地资源.在webpack的构建中,我们通常使用给文件添加后缀值来改名以及提取公共代码到不会改变 ...

  2. IIS发布获取apk文件,部署IIS遇到的问题记录

    今天需要帮着测试一下PDA的检测更新功能,所以需要把web部署到IIS上. 在部署的时候,遇到了两个小问题. 一.web 服务器被配置为不列出此目录的内容. 解决办法:1.按照提示的可尝试操作,启用了 ...

  3. WPF常规表单验证

    1:ViewModel 实现验证接口 IDataErrorInfo 2:实现接口的相关验证逻辑,并把错误信息反馈给 Error public string this[string columnName ...

  4. Http,Socket,TCP/IP 协议简述

    Http,Socket,TCP/IP 协议简述:https://blog.csdn.net/gordohu/article/details/54097841 TCP/IP协议,HTTP协议与webSo ...

  5. python-装饰器初识,闭包

    函数名的运⽤, 第⼀类对象 ⼀. 函数名的运⽤. 函数名是⼀个变量, 但它是⼀个特殊的变量, 与括号配合可以执⾏函数的变量 1. 函数名的内存地址 def func(): print("呵呵 ...

  6. Nginx反向代理与负载均衡应用实践(一)

    Nginx反向代理与负载均衡应用实践(一) 链接:https://pan.baidu.com/s/1xB20bnuanh0Avs4kwRpSXQ 提取码:migq 复制这段内容后打开百度网盘手机App ...

  7. 【学术篇】NOI2015 品酒大会 后缀数组+并查集

    省选前大致是刷不了几道题了... 所以就找一些裸一点的题目练练板子算了= = 然而这题一点都不裸, 也并不怎么好写... 于是就浪费了将近一下午的时间... 然而还不是因为后缀数组板子不熟= = 首先 ...

  8. rabbitmq AmqpClient 使用Topic 交换机投递与接收消息,C++代码示例

    // strUri = "amqp://guest:guest@192.168.30.11:8820/test" // strUri = "amqp://[帐户名]:[密 ...

  9. 第1篇Kubernetes介绍

      一.Kubernetes 介绍:     kubernetes起源 Kubernetes (K8s) 是 Google 在 2014 年发布的一个开源项目. 据说 Google 的数据中心里运行着 ...

  10. nodejs 静态资源文件与登陆交互

    server2.js var express=require('express'); var expressStatic=require('express-static'); var server=e ...