当前位置:网站首页>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
边栏推荐
- Wechat applet cloud function does not have dependency option installed
- Read multiple associations from a field using delimiters in laravel
- On Oracle full stack virtual machine -- graalvm
- 二、HikariCP獲取連接流程源碼分析二
- 在打新債開戶證券安全嗎?低傭金靠譜嗎
- PAT B1057
- PAT B1067
- RPM package installation command
- Dependency injection in PHP reflection implementation framework
- Record Baidu search optimization thinking analysis
猜你喜欢

PHP Chinese regular

Vulnhub range - darkhole 1

Jsonp function encapsulation

Web components - Basics

200 OK (from memory cache) and 200 OK (from disk cache)

Process of vacuum and vacuum full

Determine whether it is a web page opened on wechat

Vulnhub range - correlation:2

Laravel validation rule followed Role of auth:: id()

Applet canvas generate sharing Poster
随机推荐
Bloom filter
Vulnhub range - darkhole 1
Appearance of object attributes
6、 Configuration resolution of hikariconfig
Many varieties of EA can be used
Vulnhub range - correlation:2
Network security detection and prevention test questions (V)
Hdoj topic 2005 day
DataX script task development record
PAT B1071
Principles of MySQL clustered index and non clustered index
ECS 7-day practical training camp (Advanced route) -- day04 -- build a portal using ECs and polardb
MySQL prompt performance_ Schema missing table
Jsonp processing non homologous
Genicam gentl standard ver1.5 (1)
Divine reversion EA
Print 1 cute every 100 milliseconds ~ with a running lantern effect
Number of wechat applet custom input boxes
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2
2.14(Knight Moves)