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> # ...
随机推荐
- OpenCV——mixChannels函数
mixChannels Copies specified channels from input arrays to the specified channels of output arrays. ...
- 手机端的META你知道多少?
一.天猫 <title>天猫触屏版</title> <meta content="text/html; charset=utf-8" http-equ ...
- HAProxy与varnish
Even if HAProxy can do TCP proxying, it is often used in front of web application, exactly where we ...
- JS调用OC方法
- (void)myMethod:(CDVInvokedUrlCommand*)command { NSString* echo = [command.arguments objectAtIndex: ...
- LinuxIP地址、网卡相关、克隆、VM
改IP地址(#setup) 1.输入vi /etc/sysconfig/network-scripts/ifcfg-eth0 2.里面的内容修改为 DEVICE=eth0HWADDR=FC:4D:D4 ...
- log4net发布时assembly引用错误的问题
网上的通行配置: 无论BS还是CS程序都可直接在项目的AssemblyInfo.cs文件里添加以下的语句: [assembly: log4net.Config .XmlConfigurator()] ...
- masonry框架的使用之-多个视图的均匀等间距分布
__weak typeof(self) weakSelf = self; //对self进行weak化,否则造成循环引用无法释放controller UIView * tempView = [[UIV ...
- 转: Windows如何打开和使用事件查看器管理计算机
方法/步骤 1 右键单击"我的电脑"(win8中名称为"这台电脑.This Computer"),选择"管理",点击. 步骤阅读 2 出 ...
- php 弹窗插件
index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...
- linux 进程命令
Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...