当前位置:网站首页>C language PTA -- continuity factor
C language PTA -- continuity factor
2022-06-25 19:57:00 【Make the best of the time】
7-7 Continuous factor (20 branch )
The title is as you can see on your screen
I know you may have some difficulties now , No problem , Keep reading , I'm sure you can see clearly
sample input :
630
sample output :
3
5*6*7
The code is as follows :
#include<stdlib.h>
#include<math.h>
int main() {
int n,i,j,first=0,max_length=0,fact,f=0,length=0;
scanf("%d",&n);
for(i=2; i<=sqrt(n); i++) { // It must be prescribed , Otherwise, the operation will time out
fact=1;
length=0;
f=i;
for(j=i; n%j==0&&n%(fact*j)==0; j++) {
length++;
fact=fact*j;
}
// Change and ml
if(length>max_length) {
first=f;
max_length=length;
}
}
// Printout
//printf("f=%d first=%d\n",f,first);
if(max_length==0)
printf("%d\n%d\n",1,n);
else {
printf("%d\n",max_length);
for(i=first; i<first+max_length-1; i++) {
printf("%d*",i);
}
printf("%d\n",i);
}
return 0;
}Thinking analysis :
1、 With 630=3*5*6*7 For example , factor “3” Not the most critical , The focus is on output 5*6*7;
2、 As shown in the figure above , This code is created by 3 Section composition :
(1) Ergodic factor , Satisfy n% The present factor ==0;
(2) Find the maximum length , And the assignment , Pay attention to this if It's on the second for Outside of the loop ;
(3) Printout
边栏推荐
- Laravel validation rule followed Role of auth:: id()
- Vulnhub range - darkhole 1
- Jump jump games auxiliary (manual version) py code implementation
- Pdf file download (the download name is the same as the file name)
- Verification code native JS canvas
- Please do not call Page constructor in files
- Pat b1054 average (20 points)
- Network security detection and prevention test questions (V)
- Appearance of object attributes
- Huawei released two promotion plans to promote AI talent development and scientific research innovation
猜你喜欢

Applet password input box

Determine whether it is a web page opened on wechat

Arduino read temperature

Hdoj topic 2005 day

SEO outsourcing reliable company, enterprise SEO outsourcing company which reliable?

PAT B1086

Profile path and name

The native JS mobile phone sends SMS cases. After clicking the button, the mobile phone number verification code is sent. The button needs to be disabled and re enabled after 60 seconds

Wechat applet cloud function does not have dependency option installed

PHP synchronizes website content to hundreds of websites to improve SEO ranking
随机推荐
Is it safe to open a new bond? Is low commission reliable
PAT B1066
How to understand var = a = b = C = 9? How to pre parse?
Jump jump games auxiliary (manual version) py code implementation
Yaml configuration
Determine whether it is a web page opened on wechat
Install spoole
Simple native JS tab bar switching
Google cloud SSH enable root password login
Vulnhub range the planes:earth
PostgreSQL user role permissions
Divine reversion EA
Wechat applet cloud function does not have dependency option installed
JS get the parameters in the URL link
PHP database connection version1.1
PostgreSQL division considerations
Principles of MySQL clustered index and non clustered index
PAT B1056
Arduino ide + esp8266+mqtt subscribe to publish temperature and humidity information
Go language installation and uninstallation