题意:

输入一个正整数N(范围为long int),输出它等于哪些质数的乘积。

trick:

如果N为1,直接输出1即可,数据点3存在这样的数据。

如果N本身是一个质数,直接输出它等于自己即可,数据点4存在这样的数据。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int ans[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin>>n;
long long x=n;
int num=;
for(int i=;1ll*i*i<=n;++i){
if(x==)
break;
while(x%(1ll*i)==){
x/=1ll*i;
++ans[i];
++num;
if(x==)
break;
}
}
if(num==){
cout<<n<<"="<<n;
return ;
}
cout<<n<<"=";
int flag=;
for(int i=;i*i<=n;++i)
if(ans[i]){
if(flag)
cout<<"*";
cout<<i;
if(ans[i]>)
cout<<"^"<<ans[i];
flag=;
}
return ;
}

【PAT甲级】1059 Prime Factors (25 分)的更多相关文章

  1. PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)

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

  2. 1059 Prime Factors (25分)

    1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...

  3. PAT 甲级 1059 Prime Factors

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

  4. PAT Advanced 1059 Prime Factors (25) [素数表的建⽴]

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

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

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

  6. 1059. Prime Factors (25)

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

  7. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  8. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  9. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

随机推荐

  1. Winform遍历窗口的所有控件(几种方式实现)

    本文链接:https://blog.csdn.net/u014453443/article/details/85088733 扣扣技术交流群:460189483 C#遍历窗体所有控件或某类型所有控件 ...

  2. 2.2 selenium:org.openqa.selenium.WebDriverException: f.QueryInterface is not a function

    来源: http://blog.csdn.net/qiyueqinglian/article/details/47813271 URL中地址写不全的时候,就会报如题错误. url必须是完整的,比如ht ...

  3. Ansible - playbook - 概要

    概述 简单描述 ansible playbook 1. playbook 概述 ansible 的 "脚本" 场景 ansible 单条命令, 执行一个操作 问题 如果执行多个操作 ...

  4. MySQL数据完整性

    数据完整性 一个数据库就是一个完整的业务单元,可以包含多张表,数据被存储在表中 在表中为了更加准确的存储数据,保证数据的正确有效,可以在创建表的时候,为表添加一些强制性的验证,包括数据字段的类型.约束 ...

  5. PHP基础学习笔记1

    一.基本语法 1.1 形式 PHP 脚本以 <?php 开始,以 ?> 结束: <?php //php代码 ?> 1.2 注释 单行注释 //这是单行注释 多行注释 /* 这是 ...

  6. mysql学习笔记(四):group by,limit,to_days(),from_days()

    1. [Err] 1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated co ...

  7. eclipse中怎么导入git库下载下来的web项目

    总的看来是有两种方式: 方式一:可以对已经从版本库下载到本地的项目操作(Maven导入) 你可以通过公司提供的内部的版本库的网址登录版本库,之后在里面下载自己想要的那个版本的代码包,见下图 点击右侧的 ...

  8. java知识树

    https://blog.csdn.net/aitaozi11/article/details/79652943 (学习Java的9张思维导图) 文章目录 针对技术栈学习 1. java基础 1.1 ...

  9. mysql测试点

    前言 性能测试过程中,数据库相关指标的监控是不可忽视的,在这里我们就MySQL的监控配置及重点涉及性能的一些参数进行说明. 在笔者的日常性能测试过程中,重点关注了这些参数,但不代表仅仅只有这些参数对性 ...

  10. sping中AOP

    委托代理的概念: 委托类对象就是我们后面说到的"目标对象", 也就是需要[被]代理的对象 target代理类对象就是我们后面说到的"代理对象",目标对象就是需要 ...