给你一个数N,需要你算出这个数所有约数的和。(N的约数指能整除N的正整数),例如12的约数有1,2,3,4,6,12。所以约数和为1+2+3+4+6+12=28
题解:
注意:
计算出结果的数记录下来,有可能有重复的。
代码:
vara:array[0..5000001] of longint;n,s,i,j,ans:longint;
beginreadln(n);for i:=1 to n dobeginreadln(s);ans:=0;if a[s]>0 thenbeginwriteln(a[s]);continue;endelsebeginfor j:=1 to trunc(sqrt(s)) doif s mod j=0 thenif j=s div j thenans:=ans+jelse ans:=ans+j+s div j;a[s]:=ans;writeln(ans);end;end;
end.

