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的更多相关文章

  1. SPOJ 74. Divisor Summation 分解数字的因子

    本题有两个难点: 1 大量的数据输入.没处理好就超时 - 这里使用buffer解决 2 因子分解的算法 a)暴力法超时 b)使用sieve(筛子),只是当中的算法逻辑也挺不easy搞对的. 数值N因子 ...

  2. zoj 2095 Divisor Summation

    和 hdu 1215 一个意思// 只是我 1坑了 1 时应该为0 #include <iostream> #include <math.h> #include <map ...

  3. spoj 1029 Matrix Summation

    题意: 对一个矩阵有2种操作: 1.把某个元素设为x. 2.查询以(x1,y1)为左上角 以(x2,y2)为右上角的矩阵中的数字的和. 思路: 二维树状数组入门题,同时对横坐标和纵坐标做前缀和就行了. ...

  4. SPOJ 1029 Matrix Summation【 二维树状数组 】

    题意:二维树状数组,更改值的时候有一点不一样, 是将a[x][y]设置为一个值,所以add的时候要将它和以前的值作差一下 #include<iostream> #include<cs ...

  5. Divisor Summation_

    Divisor Summation Problem Description Give a natural number n (1 <= n <= 500000), please tell ...

  6. 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 ...

  7. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  8. 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 ...

  9. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

随机推荐

  1. jsp九大内置对象响应类型

     内置对象            类型request            httpServletRequestout                jspWriterresponse         ...

  2. nodejs 快要变成爬虫界的王者

    nodejs 快要变成爬虫界的王者 爬虫这东西是很多数据采集必须要的东西. 但是现在随着网页不断发展,已经出现了出单纯的网页,到 ajax 网页, 再到 spa , 再到 websocket 应用,一 ...

  3. vim编辑器高级应用

    1. vim主要模式介绍 命令模式.命令行模式.编辑模式 字符操作:i 当前插入, I行首插入, a当前字符之后插入,A行首插入, ESC退出当前模式 2. vim命令模式 3. vim插入模式 4. ...

  4. Number of 1 BitsWrite a function that takes an unsigned integer and returns the number of ’1' bits i

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...

  5. 【extjs6学习笔记】0.2 准备:类库结构

  6. 保存 http request 的数据到数据库表

    开发需求:把 http request 对象的数据保存到数据库中 第一步:编写 RequestInfoService 类,保存方法名是 saveRequestInfo // 保存request信息 p ...

  7. HTML5文档结构 摘要

    <!DOCType html>--声明文档结构类型 <html lang=zh-cn> <head> <meta charset=utf-8> < ...

  8. eclipse报错MA

    今天有个总监晒了张tomcat7.0崩溃忘记怎么搞了,大家都在吐槽"一个[总监](经常水群)竟然不会这个".敲上来. Problem Occurred系列: 'Starting T ...

  9. java多线程---ReentrantLock源码分析

    ReentrantLock源码分析 基础知识复习 synchronized和lock的区别 synchronized是非公平锁,无法保证线程按照申请锁的顺序获得锁,而Lock锁提供了可选参数,可以配置 ...

  10. 分布式文件系统ceph介绍

    ceph哲学思想 1. 每个组件必须支持扩展 2.不存在单点故障 3.解决方案必须是基于软件的.开源的.适应能力强 4.任何可能的一切必须自我管理 存在的意义:帮助企业摆脱昂贵的专属硬件 ceph目标 ...