ACM——完数
完数
时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
总提交:1930
测试通过:413
描述
自然数中,完数寥若晨星,请在从1到某个整数范围中打印出所有的完数来。所谓“完数”是指一个数恰好等于它的所有不同因子之和。例如,6是完数,因为6=1+2+3。而24不是完数,因为24≠1+2+3+4+6+8+12=36。
输入
输入数据中含有一些整数n(1<n<10000)。
输出
对于每个整数n,输出所有不大于n的完数。每个整数n的输出由n引导,跟上冒号,然后是由空格开道的一个个完数,每个n的完数列表应占独立的一行。
样例输入
100
5000
样例输出
100: 6 28
5000: 6 28 496
#include <iostream>
#include <vector>
using namespace std; int main()
{
vector<int> a;
for(int i=;i<;i++)
{
int sum=;
for(int j=;j<=i/;j++)
{
if(i%j==) sum=sum+j;
}
if(sum==i) a.push_back(i);
} int n;
while(cin>>n)
{
cout<<n<<":";
for(int i=;i<a.size();i++)
{
if(a[i]<=n) cout<<" "<<a[i];
}
cout<<endl;
}
return ;
}
ACM——完数的更多相关文章
- acm水题3个:1.求最大公约数;2.水仙花数;3.判断完数
//7.求两个整数的最大公约数#include<stdio.h>//用穷举法求出最大公约数int gcd1(int m,int n){ int min = m > n ? n : m ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-B-Perfect Numbers(完数)
题目描述 We consider a positive integer perfect, if and only if it is equal to the sum of its positive d ...
- nyist 597 完数?
http://acm.nyist.net/JudgeOnline/problem.php?pid=597 完数? 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 一个 ...
- HDU-1406 完数
http://acm.hdu.edu.cn/showproblem.php?pid=1406 完数 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- 题解报告:hdu 1406 完数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1406 Problem Description 完数的定义:如果一个大于1的正整数的所有因子之和等于它的 ...
- HDU 1406 完数 因子的和
http://acm.hdu.edu.cn/showproblem.php?pid=1406 完数的定义:如果一个大于1的正整数的所有因子之和等于它的本身,则称这个数是完数,比如6,28都是完数:6= ...
- java程序设计之完数
题目:一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程 找出1000以内的所有完数. 解题过程也很简单: public class wanshu { ...
- 程序设计入门——C语言 第6周编程练习 2 完数(5分)
2 完数(5分) 题目内容: 一个正整数的因子是所有可以整除它的正整数.而一个数如果恰好等于除它本身外的因子之和,这个数就称为完数.例如6=1+2+3(6的因子是1,2,3). 现在,你要写一个程序, ...
- OpenMP求完数
源代码: #include "stdafx.h" //必须写在首行,因为其前面的include都会被忽略 #include "omp.h" #include & ...
随机推荐
- POJ 2570
思路:floyd + 位运算.map[i][j]的二进制位前26位表示i到j路径里面字母a-z的存在情况,为1说明该字母存在,为0不存在. #include<iostream> #incl ...
- java 产生随机数
package edu.sjtu.erplab.io; import java.util.Random; public class RandomTest { public static void ma ...
- boost库的使用(一)
参考http://www.cnblogs.com/lexus/archive/2012/07/15/2592250.html bjam stage --without-python --toolset ...
- Linux中的权限管理
touch 11.txt(创建了一个文件) chown zhangsan:zhangsan 11.txt ll(可看到11.txt的属主和属组都改为了zhangsan) useradd lisi(添加 ...
- 【CSS3】Advanced5:At Rules:@import, @media, and @font-face
1.@import bolt another stylesheet onto your existing one. @import url(**.css); must be placed at the ...
- Java笔记(二)……Hello world!
编写源文件 将Java代码编写到扩展名为.java的文件中,此文件称为源文件. 1: class Hello 2: { 3: public static void main(String[] args ...
- bzoj 2285 [Sdoi2011]保密(二分,spfa + 最大流)
Description 现在,保密成为一个很重要也很困难的问题.如果没有做好,后果是严重的.比如,有个人没有自己去修电脑,又没有拆硬盘,后来的事大家都知道了. 当然,对保密最需求的当然是军方,其次才是 ...
- 如何将SQL Server运行到Windows Azure上
从2012年6月6日开始,Windows Azure上一些强大的新功能现在可用于预览,包括新的Windows Azure虚拟机(VM).其中有关Windows Azure虚拟机最强大的一件事是他们利用 ...
- java nio 快速read大文件
If you want to make your first example faster FileChannel inChannel = new FileInputStream(fileName). ...
- JavaScript- The Good Parts function Curry
Functions are values, and we can manipulate function values in interesting ways.Currying allows us t ...