当前位置:网站首页>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;
}
边栏推荐
- Object. Assign () & JS (= >) arrow function & foreach () function
- Here, the DDS tutorial you want | first experience of fastdds - source code compilation & Installation & Testing
- (2021-08-20) web crawler learning 2
- 2021-08-09
- [the way of programmer training] - 2 Perfect number calculation
- First knowledge of spark - 7000 words +15 diagrams, and learn the basic knowledge of spark
- Number and math classes
- Serialization oriented - pickle library, JSON Library
- Lvs+kept highly available cluster
- Haproxy cluster
猜你喜欢

Realize cross tenant Vnet connection through azure virtual Wan

Automatic translation between Chinese and English

SQL greatest() function instance detailed example

Simple understanding of seesion, cookies, tokens

Ultimate bug finding method - two points
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15](/img/72/0fe9cb032339d5f1ccf6f6c24edc57.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15

Btrace tells you how to debug online without restarting the JVM
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13](/img/29/49da279efed22706545929157788f0.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13

Source code analysis of the implementation mechanism of multisets in guava class library
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12](/img/b1/926d9b3d7ce9c5104f3e81974eef07.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
随机推荐
priority_ queue
Sys module
In 2022, financial products are not guaranteed?
2018 meisai modeling summary +latex standard meisai template sharing
Test question bank management system - database design [easy to understand]
QQ group collection
CSDN documentation specification
Object. Assign () & JS (= >) arrow function & foreach () function
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
MySQL advanced review
Configure SSH certificate login
[Android reverse] function interception instance (③ refresh CPU cache | ④ process interception function | ⑤ return specific results)
Configure SSH key to realize login free
(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
Application of slice
Simple understanding of string
QQ set group information
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
(2021-08-20) web crawler learning 2