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> # ...
随机推荐
- [VC++]用CTime类得到当前日期、时间、星期,格式化(详细讲解)
用CTime类得到当前日期.时间.星期,格式化(详细讲解)2009/05/12 09:48 A.M.① 定义一个CTime类对象 CTime time; ② 得到当前时间 time = CTime:: ...
- document.domain的修改问题
有时候,需要修改document.domain. 典型的情形:http://a.xxx.com/A.htm 的主页面有一个<iframe src="http://b.xxx.com/B ...
- adb 卸载android系统程序
下面是通过 pm list packages -f 列出手机中的软件,然后跟模拟器中的软件进行对比后得出的可以安全卸载的列表. 注意:卸载之后就没有Google Market了,还想用google ...
- sql中 replace函数
例用 xxx 替换 abcdefghi 中的字符串 cde. SELECT REPLACE(''abcdefghicde'',''cde'',''xxx'')
- Asp:Cookies应用指南
实际上,在web开发中,cookie仅仅是一个文本文件,当用户访问站点时,它就被存储在用户使用的计算机上,其中,保存了 一些信息,当用户日后再次访问这个站点时,web可以将这些信息提取出来. 尽 ...
- JNI调用问题(部分机型崩溃)
1.今日测试发现在部分手机上游戏会崩溃,通过logcat日志发现是jni调用问题(我猜测) 错误日志中有如下语句: trying to work around app JNI bugs, but di ...
- Haproxy的安装和配置示例
1.ha proxy简介ha proxy是一个开源的,高性能的,基于tcp第四层和http第七层应用的负载均衡软件优点:可靠性和稳定性非常好 最高可以同时维护40000-50000个 ...
- php 四种基础的算法 ---- 冒泡排序法
1. 冒泡排序法 * 思路分析:法如其名,就是像冒泡一样,每次从数组当中 冒一个最大的数出来. * 比如:2,4,1 // 第一次 冒出的泡是4 * ...
- java vector 和ArrayList的区别
相同点: 1.都是使用数组存储数据 不同点: 1.Vector是显示安全的,ArrayList是线程不安全的 Vector部分代码: public synchronized boolean add(E ...
- AutoTile 自动拼接(一) 学习与实践
恩,大家好,这两天江苏冷空气袭击,下了今年 第一场第二场雪. 不过今天我要说的 ,和 上面的 屁关系都没有. 今天要说的是 2d无缝自动拼接.大家有没有玩过 RPG Maker VX Ace. 类似 ...