当前位置:网站首页>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;
}
边栏推荐
- SAP ui5 date type sap ui. model. type. Analysis of the display format of date
- Ultimate bug finding method - two points
- Number and math classes
- Lecture 9
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
- Automatic translation between Chinese and English
- AI should take code agriculture? Deepmind offers a programming version of "Alpha dog" alphacode that surpasses nearly half of programmers!
- No response after heartbeat startup
- [ES6] template string: `string`, a new symbol in es2015
- C language memory layout
猜你喜欢
Force buckle 142 Circular linked list II
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
Alibaba cloud server connection intranet operation
QQ group administrators
Summary of Shanghai Jiaotong University postgraduate entrance examination module -- cryptography
Introduction of network security research direction of Shanghai Jiaotong University
What if the chat record is gone? How to restore wechat chat records on Apple Mobile
Reptile learning winter vacation series (2)
[the way of programmer training] - 2 Perfect number calculation
[solve the error of this pointing in the applet] SetData of undefined
随机推荐
2021-11-02
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
QQ get group member operation time
Exness: positive I win, negative you lose
Lvs+kept realizes four layers of load and high availability
MySQL advanced (Advanced) SQL statement
Four sorts: bubble, select, insert, count
Iframe to only show a certain part of the page
CSDN documentation specification
LxC shared directory addition and deletion
Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early
2021 annual summary - it seems that I have done everything except studying hard
Xshell's ssh server rejected the password, failed to skip publickey authentication, and did not register with the server
Properties and methods of OS Library
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
Possible to restore a backup of SQL Server 2014 on SQL Server 2012?
[solve the error of this pointing in the applet] SetData of undefined
Snowflake won the 2021 annual database
Data communication and network: ch13 Ethernet
Iptables cause heartbeat brain fissure