当前位置:网站首页>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;
}
边栏推荐
- Customized version of cacti host template
- Clion configuration of opencv
- First knowledge of spark - 7000 words +15 diagrams, and learn the basic knowledge of spark
- Reptile learning 4 winter vacation series (3)
- 2021-11-02
- LVS load balancing cluster deployment - Dr direct routing mode
- What if the chat record is gone? How to restore wechat chat records on Apple Mobile
- Ultimate bug finding method - two points
- Simple understanding of generics
- AI should take code agriculture? Deepmind offers a programming version of "Alpha dog" alphacode that surpasses nearly half of programmers!
猜你喜欢

Simple understanding of seesion, cookies, tokens

(August 10, 2021) web crawler learning - Chinese University ranking directed crawler

LVS load balancing cluster deployment - Dr direct routing mode

The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history

Decrypt the advantages of low code and unlock efficient application development

Leetcode: 408 sliding window median

OSI model notes

Day01 preliminary packet capture

Attributes and methods in math library

SQL greatest() function instance detailed example
随机推荐
2021-11-02
Enter the smart Park, and change begins here
Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Games101 Lesson 8 shading 2 Notes
Reptile learning 4 winter vacation learning series (1)
(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
Video analysis
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
Detailed array expansion analysis --- take you step by step analysis
2021-10-20
Solaris 10 network services
MySQL advanced (Advanced) SQL statement
Method of setting default items in C # ComboBox control code
Single spa, Qiankun, Friday access practice
QQ get group settings
Experiment 7. IPv6
OSI seven layer model & unit
Common tips
Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early