【问题描小新一起共进晚餐 pascal 习题

[复制链接]
查看11 | 回复3 | 2012-3-22 20:20:59 | 显示全部楼层 |阅读模式
测试 1s内可以通过10的9次方2497558338思想:因为一个数的一对因数必定是一大一小,小的因数最大值不会超过根号下(n)所以,穷举小的因数,时间代价是O(SQRT(N)) 注:int64是free pascal下的整数类型,比longint大varn,m,i:longint;ans:int64;beginread(n);m:=trunc(sqrt(n));ans:=0;for i:=1 to m do
if n mod i =0 then
ans:=ans+i+(n div i);if (m*m)=n then ans:=ans-m;writeln(ans);...
回复

使用道具 举报

千问 | 2012-3-22 20:20:59 | 显示全部楼层
Var i,n,sum,j:integer;a:array[1..200]of boolean;beginread(n);sum:=0;for i:=1 to n do a:=false;for j:=1 to n doif n div j=0 then a[j]:=true;for i:=1 to n do if a[...
回复

使用道具 举报

千问 | 2012-3-22 20:20:59 | 显示全部楼层
var s:qword;
n,i:longint;begin readln(n): for i:=1 to trunc(sqrt(n)) doif n mod i=0 then s:=s+i; writeln(s);end....
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行