SPOJ DIVSUM - Divisor Summation
DIVSUM - Divisor Summation
Given a natural number n (1 <= n <= 500000), please output the summation of all its proper divisors.
Definition: A proper divisor of a natural number is the divisor that is strictly less than the number.
e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor summation is: 1 + 2 + 4 + 5 + 10 = 22.
Input
An integer stating the number of test cases (equal to about 200000), and that many lines follow, each containing one integer between 1 and 500000 inclusive.
Output
One integer each line: the divisor summation of the integer given respectively.
Example
Sample Input:
3
2
10
20 Sample Output:
1
8
22
Warning: large Input/Output data, be careful with certain languages
解题:第一道用RUST写的水题,RUST的效率真心不敢恭维,尤其是IO效率
use std::io;
use std::io::prelude::*;
fn main(){
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let n = lines.next().unwrap().unwrap().parse::<i32>().unwrap();
for _ in ..n {
let mut x = ;
let mut sum = ;
let y = lines.next().unwrap().unwrap().parse::<i32>().unwrap();
while x*x <= y {
if y%x == {
let tmp = y/x;
if x != y {
sum += x;
}
if tmp != x && tmp != y {
sum += tmp;
}
}
x = x + ;
}
println!("{}",sum);
}
}
SPOJ DIVSUM - Divisor Summation的更多相关文章
- SPOJ 74. Divisor Summation 分解数字的因子
本题有两个难点: 1 大量的数据输入.没处理好就超时 - 这里使用buffer解决 2 因子分解的算法 a)暴力法超时 b)使用sieve(筛子),只是当中的算法逻辑也挺不easy搞对的. 数值N因子 ...
- zoj 2095 Divisor Summation
和 hdu 1215 一个意思// 只是我 1坑了 1 时应该为0 #include <iostream> #include <math.h> #include <map ...
- spoj 1029 Matrix Summation
题意: 对一个矩阵有2种操作: 1.把某个元素设为x. 2.查询以(x1,y1)为左上角 以(x2,y2)为右上角的矩阵中的数字的和. 思路: 二维树状数组入门题,同时对横坐标和纵坐标做前缀和就行了. ...
- SPOJ 1029 Matrix Summation【 二维树状数组 】
题意:二维树状数组,更改值的时候有一点不一样, 是将a[x][y]设置为一个值,所以add的时候要将它和以前的值作差一下 #include<iostream> #include<cs ...
- Divisor Summation_
Divisor Summation Problem Description Give a natural number n (1 <= n <= 500000), please tell ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
随机推荐
- Semi-prime H-numbers
题目描述形如4n+1的数被称为“H数”,乘法在“H数”集合内为封闭的.因数只有1和本身的数叫“H素数”(不包括1),其余叫“H合数”.一个“H合成数”能且只能分解为两个“H素数”.求0·h内的“H合成 ...
- 浅析ES6中的iterator
1.iterator迭代器必须保证其遍历终止条件可控,否则会形成死循环demo: //会用到iterator接口的场合 //1.for...of循环 //2. ...解构表达式 const obj = ...
- QT如何设置应用程序的图标
QT如何设置应用程序的图标 准备:.ico格式的图片,可以选择任意其他图片格式的一张图片用格式工厂转换成.ico图片 例如选用的图片是Application.ico 把图片放到工程目录下 在工 ...
- 使用 Visual Studio 2017 部署 Azure 应用服务的 Web 应用
本快速入门介绍了如何使用 Visual Studio 2017 创建并部署 Azure Web 应用.在本教程中完成的所有操作均符合1元试用条件. 本快速入门介绍了如何使用 Visual Studio ...
- EJB开发基础——EJB规范
1.EJB 容器 Enterprise Bean 是在称作 EJB 容器的特殊环境中运行的软件组件.容器容纳和管理 Enterprise Bean 的方式与 Java Web 服务器 ...
- LeetCode Add and Search Word - Data structure design (trie树)
题意:实现添加单词和查找单词的作用,即实现字典功能. 思路:'.' 可以代表一个任何小写字母,可能是".abc"或者"a.bc"或者"abc.&quo ...
- 洛谷 P1996 约瑟夫问题
题目背景 约瑟夫是一个无聊的人!!! 题目描述 n个人(n<=100)围成一圈,从第一个人开始报数,数到m的人出列,再由下一个人重新从1开始报数,数到m的人再出圈,……依次类推,直到所有的人都出 ...
- ubuntu14.04 red5
jdk tar -xzvf jdk-8u151-linux-x64.tar.gz nano /etc/profile export HADOOP_HOME=/usr/local/src/hadoope ...
- 激励CEO们最好的办法就是鼓励他们不要停止思考
我们应该怎样在企业中释放出每一个人都可能内在的自我驱动力呢? 我创业十多年来,结识了很多创业家,他们中很多和我一样也试图通过学习实践找到有效管理的捷径,一个最简单的法则,最好还是比较容易的.事实上,最 ...
- App Store上的开源应用汇总
以下是互联网上主要的开源iOS应用的列表,在学习的时候,多看看完成的功能代码可以给我们带来很多经验,但是除了Apple官方提供的Sample Code之外,我们很难找到优质的开源项目代码,所以我搜集了 ...