1098-a New Function
PDF (中文版) statisticsforum
Time Limit:3 second (s) Memory limit:32 MB
We all know this any integer number n are divisible by 1 and N. That's why these, numbers, and the actual divisors of any numbers. The function SOD (n) (sum of divisors) is defined as the summation of the and the actual divisors of an integer number n. For example,
SOD (24) = 2+3+4+6+8+12 = 35.
The function Csod (n) (cumulative SOD) of an integer n, is defined as below:
Given the value of N, your job is to find the value of Csod (n).
Input
Input starts with an integer T (≤1000), denoting the number of test cases.
Each case is contains an integer n (0≤n≤2 * 109).
Output
For each case, print the case number and the result. You may assume this each output would fit into a signed integer.
Sample Input
Output for Sample Input
3
2
100
200000000
Case 1:0
Case 2:3,150
Case 3:1.,289,868,120,183,71E,+16
Problem Solving Ideas:
By a factor, the other factors corresponding to this factor are calculated and summed;
For example n=20, when the factor is 2 o'clock, corresponds to 2 (4), 3 (6), 4 (8), 5 (10), 6 (12), 7 (14), 8 (16), 9 (18), 10 (10)
When 3 o'clock, corresponds to 2 (6), 3 (9), 4 (12), 5 (15), 6 (18)
In this case, be careful to avoid duplication between 2 and 3 o'clock.
#include <iostream>#include<cmath>#include<cstdio>using namespaceStd;typedefLong Longll;intt;ll sum,n,p,q,m;intMain () {scanf ("%d",&T); for(intt=1; t<=t;t++) {sum=0; scanf ("%lld",&N); M=(LL) sqrt (n); for(LL i=2; i<=m;i++) {sum+=i; //The P,Q variable is added to avoid duplication.p = i+1; Q= n/i; if(Q<Q)Continue; Sum+ = (q-p+1)*i; Sum+ = (q-p+1) * (Q+P)/2; } printf ("Case %d:%lld\n", t,sum); } return 0;}
View Code
Lightoj-1098-a New Function (Factor and)