PAT (Advanced Level) 1059. Prime Factors (25)
素因子分解。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<stack>
#include<vector>
using namespace std; long long n; bool f(long long a)
{
for(long long i=;i*i<=a;i++)
if(a%i==) return ;
return ;
} struct X
{
long long num;
int tot;
}s[]; int main()
{
scanf("%lld",&n); int g=;
printf("%lld=",n);
for(long long i=;;i++)
{
if(f(n))
{
s[g].num=n;
s[g].tot=;
g++;
break;
}
if(n%i!=) continue;
if(f(i)==) continue;
s[g].num=i; s[g].tot=;
while()
{
if(n%i==)
{
n=n/i;
s[g].tot++;
}
else break;
}
g++;
if(n==) break;
} printf("%lld",s[].num);
if(s[].tot>) printf("^%d",s[].tot);
for(int i=;i<g;i++)
{
printf("*");
printf("%lld",s[i].num);
if(s[i].tot>) printf("^%d",s[i].tot);
}
printf("\n"); return ;
}
PAT (Advanced Level) 1059. Prime Factors (25)的更多相关文章
- 【PAT甲级】1059 Prime Factors (25 分)
题意: 输入一个正整数N(范围为long int),输出它等于哪些质数的乘积. trick: 如果N为1,直接输出1即可,数据点3存在这样的数据. 如果N本身是一个质数,直接输出它等于自己即可,数据点 ...
- 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 ...
- 1059 Prime Factors (25分)
1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...
- 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 ...
- PAT 1059. Prime Factors (25) 质因子分解
题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...
- 1059. Prime Factors (25)
时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
- PAT (Advanced Level) 1096. Consecutive Factors (20)
如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
随机推荐
- opewrt上传文件
设备上运行的openwrt,当tftp和ftp都无法使用时,可以使用命令scp在两台linux设备上copy文件. 当设备启动起来后,输入命令: scp hbg@192.168.2.32:/home/ ...
- jax-rs的客户端完整实例
本地接口: @Override public Response formsubGet(String accountContent, char inputContent, S ...
- nginx php mysql 集成安装包
经过多次的苦苦寻找,终于找到一款 集成了nginx 和mysql php的包.只需一键安装即可. 且可以修改其中的nginx mysql 与php的版本. 解压此文件lnmp???ɰ?n-1.6p-5 ...
- Ansible9:条件语句【转】
在有的时候play的结果依赖于变量.fact或者是前一个任务的执行结果,从而需要使用到条件语句. 一.when 有的时候在特定的主机需要跳过特定的步骤,例如在安装包的时候,需要指定主机的操作系统 ...
- Eclipse 安装最新SVN插件
本文来源:http://liujianqiao398.blog.163.com/blog/static/181827257201331194610634/ Eclipse 安装最新SVN插件 2013 ...
- rebar
www.cnblogs.com/panfeng412/archive/2011/08/14/2137990.html
- sql查询百分号的方法
select * from [tablename] where [col] like '%100/%%' escape '/'
- zf-关于更换页面,的各种问题。
问题1:找不到common 这个变量(集合)与layer这个js文件. 这里的common 就是一个方法集合,声明var common; common.abc = function(参数1,参数2, ...
- java操作oracle的blob,clob数据
一.区别和定义 LONG: 可变长的字符串数据,最长2G,LONG具有VARCHAR2列的特性,可以存储长文本一个表中最多一个LONG列 LONG RAW: 可变长二进制数据,最长2G CLOB: ...
- 事件委托小demo(jq版)
<style type="text/css"> * { margin:; padding:; } .box1 { width: 200px; height: 60px; ...