ACM-求质因数
求输入数字的所有质因数,并将所有质因数进行排序,并以质因数+空格的形式输出
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
static int cou;
int result[] = {};
void Rank(int add[],int n) //将求得的质因数进行冒泡排序,从小到大
{
int i,j,num;
for(i=;i<n-;i++){
for(j=;j<=n-i-;j++){
if(add[j]>add[j+])
{
num = add[j];
add[j] = add[j+];
add[j+] = num;
}
}
}
}
void getResult(long num) //求质因数算法
{
cou = ;
for(int i = ;i <= num;i++)
{
if(num%i == ){
result[cou++] = i;
num = num/i;
i = ;
}
}
Rank(result,cou);
} int main()
{
long int num;
scanf("%d",&num);
getResult(num);
for(int i = ;i < cou;i++)
{
printf("%d ",result[i]);
}
printf("\r");
return ;
}
ACM-求质因数的更多相关文章
- 2.C# 输入一个整数,求质因数
C# 输入一个整数,求质因数 List<int> results = new List<int>(); int number = Int32.Parse(Console.Rea ...
- CF1444A Division 求质因数的方法
2020.12.20 求质因数的方法 CF1444A Division #include<bits/stdc++.h> #define ll long long #define fp(i, ...
- C# 输入一个整数,求质因数
质数,质因数 应该都了解,在这里不过多解释,直接上代码: List<int> results = new List<int>(); int number = Int32.Par ...
- Number Sequence(hdu4390)
Number Sequence Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- TYVJ P1020 寻找质因数
做题记录:2016-08-08 描述 给出N个数字,试求质因数最大的数字. 输入格式 第一行,一个整数N,表示数字个数.接下来N行,每行一个整数A_i,表示给出的数字. 输出格式 一个整数,表示质因数 ...
- UVA 11610 Reverse Prime (数论+树状数组+二分,难题)
参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...
- linux c 分解质因数
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> ...
- HDU 1405 第六周 J题
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all ...
- hdu 1695 GCD(欧拉函数+容斥)
Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD( ...
- HDU 6069
Counting Divisors Problem Description In mathematics, the function d(n) denotes the number of diviso ...
随机推荐
- Python numpy tensorflow 中的 点乘 和 矩阵乘法
1)点乘(即“ * ”) ---- 各个矩阵对应元素做乘法 若 w 为 m*1 的矩阵,x 为 m*n 的矩阵,那么通过点乘结果就会得到一个 m*n 的矩阵. 若 w 为 m*n 的矩阵,x 为 m ...
- Linux设置免密登陆
生成秘钥 ssh-keygen -t rsa -C "XX@qq.com",然后一路回车就行 生成之后会在用户的根目录生成一个 ".ssh"的文件夹 进入&qu ...
- Codeforces Round #603 (Div. 2)
传送门 感觉脑子还是转得太慢了QAQ,一些问题老是想得很慢... A. Sweet Problem 签到. Code /* * Author: heyuhhh * Created Time: 2019 ...
- 201871010124 王生涛《面向对象程序设计JAVA》第一周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://edu.cnblogs.com/campus/xbsf/ ...
- maven help 插件
maven help 插件 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins&l ...
- Noip2016Day2T3 愤怒的小鸟
题目链接 problem 平面内有n个点,每次可以确定一条过原点且开口向上的抛物线,将这条抛物线上所有的点都删去.问最少需要删几次可以删掉全部的点. solution n比较小,直接状压一下.因为已经 ...
- Redis高可用集群-哨兵模式(Redis-Sentinel)
前言 Redis哨兵模式,用现在流行的话可以说就是一个“哨兵机器人”,给“哨兵机器人”进行相应的配置之后,这个"机器人"可以7*24小时工作,它能能够自动帮助你做一些事情,如监控 ...
- Protractor - 环境设置
去年出于好奇搭建过一个Protractor+Cucumber的测试框架,当时项目上并没有用到AngularJS,所以框架能运行起来之后没有再深入了.最近新项目引入了AngularJS,想起去年搭的那个 ...
- 记一次收集APP native崩溃信息
最近在学习 极客时间Android开发高手课 老师推荐了Breakpad开源库来采集native 的crash1.为什么要使用Google Breakpad? 我们在开发过程中,Android JNI ...
- 英语阅读——A meaningful life
这篇文章是<新视野大学英语>第四册的第八单元的文章. 1 The death of an angel of animal rights activism(活动家) does not rat ...