当前位置:网站首页>Brush questions - Luogu -p1075 prime factor decomposition
Brush questions - Luogu -p1075 prime factor decomposition
2022-07-25 13:46:00 【Song Xiangshang_ UP】
P1075 Prime factor decomposition -C Language
1、 subject

2、 The problem solving process
(1) for the first time Because of the timeout Write too many cycles In particular, bubble sorting is not necessary
result :
Code :
(2) The second time Removed bubble sort But it's still overtime
Code :
// Luogu P1075 Prime factor decomposition
#include <stdio.h>
#define MAX 200
int main() {
int n;// Positive integer 1<=n<=2*10 Of 9 Power
int factor[MAX];// Factor
int prime[MAX];// Prime number
int i, j, k;
int temp;// Bubble sort temporary value
int counter = 0;// Counter Number of counting factors
scanf("%d", &n);// Enter a positive integer n
// Factor
for (i = 1; i <= n; i++) {
if (n % i == 0) {
factor[counter] = i;
counter++;
//printf("%d", i);// Factor
}
}
k = 0;// Prime subscript
// Find prime number
for (i = 0; i < counter; i++) {
// Number of factors to be processed circularly
for (j = 2; j < factor[i]; j++) {
if (factor[i] % j == 0) {
// Not prime
break;
}
}
if (j >= factor[i]) {
// Print prime
prime[k] = factor[i];
k++;
//printf("\n %d ", factor[i]);
}
}
//printf(" Maximum :%d",prime[k] );
printf("%d", prime[k-1]);
return 0;
}
(3) third time What is special about this problem is that it is set as a positive integer N Is the product of two different prime numbers .
result :
Code :
// Luogu P1075 Prime factor decomposition
#include <stdio.h>
int main() {
int n;// Positive integer 1<=n<=2*10 Of 9 Power
int i;
scanf("%d", &n);// Enter a positive integer n
if (n == 1 || n==2 || n==3) {
printf("%d", n );
return 0;
}
// Find the quality factor
for (i = 2; i <= n; i++) {
if (n % i == 0) {
printf("%d", n/i);// Factor
break;
}
}
return 0;
}
边栏推荐
猜你喜欢

MXNet对DenseNet(稠密连接网络)的实现

QGIS loading online map: Gaode, Tiandi map, etc
![[force deduction] 1030. Arrange matrix cells in distance order](/img/6d/5301be3439cdb35500cbb4ae4a2534.png)
[force deduction] 1030. Arrange matrix cells in distance order

安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1

嵌入式代码如何进行重构?

「数字安全」警惕 NFT的七大骗局

移动端网站,独立APP,网站排名策略有哪些?

Preparing for the soft test for junior programmers in the second half of 2022

Excel add key run macro

音视频技术开发周刊 | 255
随机推荐
说说对hashcode和equals方法的理解?
How happy is the frisbee bureau? 2022 youth trendy Sports Report
The interviewer asked me: how much do you know about MySQL's storage engine?
sieve of eratosthenes
Concurrent tool set for concurrent programming
Applet starts wechat payment
0710RHCSA
Mujoco+spinningup for intensive learning training quick start
What is your revenue rank among global developers in 2022?
hcip第九天笔记
@wrap 装饰器
NoSQL,关系型数据库,行列数据库对比、类比
Uniapp handles background transfer pictures
VIM basic operation summary
职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?
埃拉托斯特尼筛法
Congestion control of TCP
In order to improve efficiency, there are various problems when using parallelstream
「数字安全」警惕 NFT的七大骗局
Leetcode -- addition of four numbers II