当前位置:网站首页>Pat (advanced level) 1096 - continuous
Pat (advanced level) 1096 - continuous
2022-04-21 19:10:00 【Coco_ T_】
- Data range use int that will do
- The factor is sqrt Level of complexity , Simple violence is enough
- Prime numbers require special treatment
I unconsciously wrote the code for finding the factor at the beginning ( Number of each Judge alone Is it divisible )
But the title means , These series of factors need to be multiplied
That is, when recalculating the longest continuous factor sequence , It is necessary to accumulate the influence of various factors
a /= (cnt + i);
I also take it for granted that , The continuity factor has such a property : If tested [ a , b ] [a,b] [a,b] This sequence , Then we just need to start from b + 1 b+1 b+1 Just start the test
This is not at all wrong !
So we have to be right from 2 To sqrt Each number of i, All calculated in i The longest sequence of continuous factors starting from
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
int x;
int main()
{
scanf("%d", &x);
int cnt = 0;
int ans_cnt = 0;
int begin;
for (int i = 2; i <= sqrt(x);++i) {
if (x % i == 0) {
int a = x / i;
cnt = 1;
while (a % (cnt + i) == 0) {
a /= (cnt + i);
cnt++;
}
if (cnt > ans_cnt) {
ans_cnt = cnt;
begin = i;
}
}
}
if (ans_cnt == 0) {
printf("1\n%d",x);
}
else {
printf("%d\n", ans_cnt);
for (int i = 0; i < ans_cnt; ++i) {
printf("%d", begin + i);
if (i < ans_cnt - 1) printf("*");
}
}
return 0;
}
版权声明
本文为[Coco_ T_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211855190033.html
边栏推荐
- leetcode:423. Reconstructing numbers from English
- To deal with doget & dopost Chinese garbled code
- Introduction to GPS Beidou satellite time synchronization system (clock device) technology of power grid
- 机器学习笔记 - 迹算子(跟踪运算符)
- APM industry awareness series - IV
- Which futures trading platform is the safest? How do I choose?
- Alwaysinstallelevated
- JVM专题(十一)-垃圾回收(二)
- 影响VPS网站优化的因素有哪些?
- 2022.04.21 (lc_452_detonates the balloon with the least number of arrows)
猜你喜欢

Database advanced learning: storage engine

Cvpr2022 unified upgrade of oral | cosface and arcface, and adaface solves face recognition of low-quality images

Wide application of medical robot in AI field

Analysis of service registration source code of Nacos

Overview of u-net network deformation

Automatic control principle Chapter 5 - frequency method (mind map)

面试官:简单聊聊 Go 逃逸分析?

体育场馆系统可以连接其他智能设备吗

The CPU and memory consumption are too high, but the memory and CPU occupied by the processes in the task manager cannot be seen

Machine learning notes - Trace operator (tracking operator)
随机推荐
Ribbon原理与Nacos的服务发现原理分析
Rk3399 - add USB to serial driver
Navicat MySQL连接Linux下MySQL的及2003错误解决方案
APM 行业认知系列 - 四
Cvpr2022 unified upgrade of oral | cosface and arcface, and adaface solves face recognition of low-quality images
How to classify cosmetics in the management system?
Tensorflow from foundation to practice 00 tensor, conversation, variable, matrix
Context in programming
MusicPlayer2.1版本
To deal with doget & dopost Chinese garbled code
Which futures trading platform is the safest? How do I choose?
初等数学建模问题
力扣-53.最大子数组和
Wide application of medical robot in AI field
排序会了递归,不学非递归太可惜了
How to open the developer tool when the uniapp runs to the built-in browser
U-Net网络变形综述
Common shell commands - grep (I)
WebRTC视频无法播放,如何在EasyCVR添加UDP打洞程序?
改进模型速度/精度的工程方法