首页 > 其他分享 >1059. Prime Factors (25)

1059. Prime Factors (25)

时间:2022-11-25 14:33:39浏览次数:66  
标签:Prime 25 head 1059 sail count PrimeFactors add num


1059. Prime Factors (25)

时间限制



50 ms



内存限制



65536 kB



代码长度限制



16000 B



判题程序



Standard



作者



HE, Qinming


Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1* p2^k2 *…*pm^km.

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 = p1^k1 * p2^k2 *…*pm^km, where pi's are prime factors of N in increasing order, and the exponent ki is the number of pi -- hence when there is only one pi, ki is 1 and must NOT be printed out.


Sample Input:

97532468


Sample Output:


97532468=2^2*11*17*101*1291


这题和之前的一题很像。http://xujiayu317.blog.163.com/blog/static/2547520920149218497214/


但是这题过程中一直有个结果错误。看了那些ac的代码。发现是要当num=1时要1=1  改了一下就过了(但是1不是质数吧,这属于特殊条件)。


评测结果

时间

结果

得分

题目

语言

用时(ms)

内存(kB)

用户

7月17日 20:38

答案正确

​25​

​1059​

​C++ (g++ 4.7.2)​

1

308

​datrilla​

测试点

测试点

结果

用时(ms)

内存(kB)

得分/满分

0

答案正确

1

180

15/15

1

答案正确

1

308

4/4

2

答案正确

1

180

2/2

3

答案正确

1

180

2/2

4

答案正确

1

180

2/2

#include<iostream>
#include<math.h>
using namespace std;
class PrimeFactors
{
private:
long int e,m;
PrimeFactors* next;
public:
void printpf();
void line(long int ee,long int mm);
PrimeFactors*head,*sail;
PrimeFactors()
{
head=NULL;
sail=NULL;
}
};
void PrimeFactors::printpf()
{
cout<<head->e<<"=";
sail=head;
head=head->next;
delete sail;
while(head->next)
{
cout<<head->e;
if(head->m!=1)
{
cout<<"^"<<head->m;
}
cout<<"*";sail=head;
head=head->next;
delete sail;
}
cout<<head->e;
if(head->m!=1)
{
cout<<"^"<<head->m;
}
delete head;
cout<<endl;
head=NULL;
sail=NULL;
}
void PrimeFactors::line(long int ee,long int mm)
{
PrimeFactors*p;
if(head)
{
p=new PrimeFactors;
p->e=ee;
p->m=mm;
sail->next=p;
sail=p;
}
else
{
head=new PrimeFactors;
head->e=ee;
head->m=0;
sail=head;
}
sail->next=NULL;
}
int main()
{
PrimeFactors pf;
long int num,add,count;
cin>>num;
if(num>1)
{
pf.line(num,0);
add=2;
count=0;
while(num%add==0)
{
num/=add;
count++;
}
if(count!=0)
{
pf.line(add,count);
}
add=3;
while(num>2&&add<=sqrt(num))
{
count=0;
while(num%add==0)
{
count++;
num/=add;
}
if(count!=0)
{
pf.line(add,count);
}
add+=2;
}
if(num>2)
pf.line(num,1);
pf.printpf();
}
else cout<<num<<"="<<num<<endl;
return 0;
}



标签:Prime,25,head,1059,sail,count,PrimeFactors,add,num
From: https://blog.51cto.com/datrilla/5886674

相关文章

  • 2022-11-25Acwing每日一题
    本系列所有题目均为Acwing课的内容,发表博客既是为了学习总结,加深自己的印象,同时也是为了以后回过头来看时,不会感叹虚度光阴罢了,因此如果出现错误,欢迎大家能够指出错误,我......
  • 11.25.2
    #include<stdio.h>intmain(){ inta,n,i; unsignedlonglongsum=0; scanf("%d",&n); a=2; for(i=1;i<=n;i++) { sum+=a; a=a*10+a%10; } printf("%llu",sum)......
  • CF1251E2
    非常神的贪心,先要发现以下两个性质:要花钱收买的一些人,那么肯定是在一开始就收买他们。按照\(m\)升序排序,那么处理\(m=x\)时,\(m=1\simx-1\)的人一定都投了票,不管是......
  • C++Primer 第3章
    第3章字符串、向量和数组3.1命名空间的using声明目前为止,我们用到的库函数基本上都属于命名空间std,而程序也显式地将这一点标示了出来。例如,std::cin表示从标准输入中......
  • java工具类-jwt-RSA256算法加密
    加密数据(用户信息)packagetestJWT;/***@authorZRY*@version1.0*/publicclassUser{//用户idprivateintid;//用户名称private......
  • Unknown initial character set index '255' received from server. Initial client
    错误:Causedby:java.sql.SQLException:Unknowninitialcharactersetindex'255'receivedfromserver.Initialclientcharactersetcanbeforcedviathe'cha......
  • luogu1253 [yLOI2018] 扶苏的问题 题解
    扶苏的问题题目题目描述给定一个长度为\(n\)的序列\(a\),要求支持如下三个操作:给定区间\([l,r]\),将区间内每个数都修改为\(x\)。给定区间\([l,r]\),将区间内每......
  • ABC255Ex
    ABC255Ex*2430思路较为简单。调了一下午加一早上,发现是人眼做\(10^{18}\)级整数比大小判错了,抬走。题意给定一片\(N\)格的农田,从第\(0\)天开始,第\(i\)格农田......
  • 淘宝、天猫、1688、京东等25个平台的API数据接口
    接口大全;item_get获得淘宝商品详情item_get_app获得淘宝app商品详情原数据item_get_pro获得淘宝商品详情高级版item_review获得淘宝商品评论item_sku获取sku详细信......
  • day25
    【0347.前K个高频元素】classSolution{public:vector<int>topKFrequent(vector<int>&nums,intk){unordered_map<int,int>map;for(in......