当前位置:网站首页>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;
}
边栏推荐
- QQ get group link, QR code
- Definition and method of string
- Is Sanli futures safe? How to open a futures account? How to reduce the handling charge of futures at present?
- Recommend a cool geospatial data visualization tool with low code
- re. Sub() usage
- QQ group collection
- Reptile learning 4 winter vacation learning series (1)
- array_ The contains() function uses
- QQ get group settings
- Experiment 7. IPv6
猜你喜欢
Games101 Lesson 8 shading 2 Notes
Post man JSON script version conversion
Introduction of network security research direction of Shanghai Jiaotong University
Leetcode: 408 sliding window median
Clion configuration of opencv
DDS-YYDS
Foreach (system.out:: println) usage
Simple understanding of seesion, cookies, tokens
MySQL advanced review
Attributes and methods in math library
随机推荐
AI should take code agriculture? Deepmind offers a programming version of "Alpha dog" alphacode that surpasses nearly half of programmers!
Clion configuration of opencv
Summary of Shanghai Jiaotong University postgraduate entrance examination module -- cryptography
Haproxy cluster
Entitas learning [iv] other common knowledge points
Customized version of cacti host template
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
Understanding of object
Googgle guava ImmutableCollections
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
What if the chat record is gone? How to restore wechat chat records on Apple Mobile
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
C language memory layout
[the way of programmer training] - 2 Perfect number calculation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
Review of week 278 of leetcode II
Data communication and network: ch13 Ethernet
A few words explain redis cache penetration, breakdown, avalanche, and redis sentinel