当前位置:网站首页>Pat 1059 prime factors (25 points) prime table
Pat 1059 prime factors (25 points) prime table
2022-07-04 12:07:00 【Python ml】
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int>prime(50000,1);
int main() {
for(int i=2;i*i<50000;i++)
for(int j=2;j*i<50000;j++)
prime[j*i]=0; //50000 Any inside can be decomposed into j*i None of the numbers are prime numbers , And one of the primes i It must be less than sqrt(50000)
long int a;
scanf("%ld",&a);
printf("%ld=",a);
if(a==1)printf("1");
bool state=false;
for(int i=2;i<50000&&a>2;i++){
int cnt=0,flag=0;
while(prime[i]==1&&a%i==0){
// Factors can be decomposed from small to large i,i There may be more than one , Always cycle division i
cnt++;
a=a/i;
flag=1;
}
if(flag){
if(state)printf("*"); // The second factor begins with *
printf("%d",i);
state=true;
}
if(cnt>=2)printf("^%d",cnt);
}
if(a>1)printf("%s%ld",state?"*":"",a); //state Indicates that it can be decomposed ,a Is the last prime factor , Otherwise print directly n
system("pause");
return 0;
}
边栏推荐
- LxC shared directory addition and deletion
- Is Sanli futures safe? How to open a futures account? How to reduce the handling charge of futures at present?
- Reptile learning winter vacation series (2)
- QQ group administrators
- Simple understanding of generics
- os. Path built-in module
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
- thread
- Introduction of network security research direction of Shanghai Jiaotong University
- Detailed array expansion analysis --- take you step by step analysis
猜你喜欢
MySQL advanced review
Usage of case when then else end statement
Automatic translation between Chinese and English
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
Detailed array expansion analysis --- take you step by step analysis
The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history
Ultimate bug finding method - two points
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
What if the chat record is gone? How to restore wechat chat records on Apple Mobile
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
随机推荐
AI should take code agriculture? Deepmind offers a programming version of "Alpha dog" alphacode that surpasses nearly half of programmers!
Xiaobing · beauty appraisal
Exness: positive I win, negative you lose
Lvs+kept highly available cluster
QQ get group link, QR code
Using terminal connection in different modes of virtual machine
VPS installation virtualmin panel
2020 Summary - Magic year, magic me
Decrypt the advantages of low code and unlock efficient application development
Polymorphic system summary
Automatic translation between Chinese and English
JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup
QQ group administrators
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
Introduction of network security research direction of Shanghai Jiaotong University
re. Sub() usage
LxC shared directory addition and deletion
Data transmission in the network
Summary of collection: (to be updated)
Reptile learning 3 (winter vacation learning)