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(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
随机推荐
- postman中添加cookie信息
日常测试中有部分接口请求需要有登录信息,否则调用报错,那如何在postman中添加用户的cookie呢,主要分2个步骤: 第一步: Charles抓包获取Headers信息,拷贝Headers中的Co ...
- asp.net excel导出红色字体
文章转自网上的一位朋友,非常感谢! 后台代码 public void ExportDataTableToExcel(System.Data.DataTable s_DataTable) { int t ...
- idea 设置加载多个资源文件,显示本地图片
idea 经常只会设置一个资源路径,这个路径就是项目的路径.但是当要加载的文件处于其他位置时,则需要增加虚拟路径的配置. 如图:第一个是项目路径 第二个是图片路径
- sublime快捷键mark
Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的文本进行同时编辑)Ctrl+G 跳转到相应的行Ctrl+J 合并行(已选择需要合并的多行时)Ctrl+L 选择整行(按住-继续选择下 ...
- LR中常见请求的使用示例
Action(){ //application/x-www-form-urlencoded //application/json //web_add_auto_header("Content ...
- java后台验证码的生成
前台代码: <tr> <td>验证码</td> <td><input name="checkCode" type=" ...
- javascript的trigger事件
<html> <head> <script type="text/javascript" src="/jquery/jquery.js&qu ...
- Php教程
第一部:PHP基础部分(131集,发布完毕) 讲html与PHPt基础,PHP环境搭建,与留言本编写. 下载地址:① HTML视频[2014新版] http://pan.baidu.com/s/1ve ...
- 电商技术中企业数据总线ESB和注册服务管理的区别
一.概述 1.什么是ESB 就是企业数据总线的意思,他的核心功能就是兼容各种协议接口,可以将数据在各种协议之间进行流转,并且可以针对数据格式进行编排转换. 异构系统,功能繁多,复杂 代表性的项目有:J ...
- 简单css动画 fadeIn fadeOut flash
考虑兼容性采用 -webkit- -o- -mos- -ms- @keyframes fadeIn{ 0%{ opacity: 0; display: block; } 100%{ opacity: ...