SOS!!!怎么都超时了

var
a,b,i,j,n:longint;
function as(a,b:longint):longint;
var
q,w:longint;
i:longint;
begin
for i:=1 to (a div 2) do
if a mod i = 0 then
q:=q+i+(a div i);
for i:=1 to (b div 2) do
if b mod i = 0 then
w:=w+i+(b div i);
if q=w then as:=1;
end;
begin
read(a,b);
for i:=a to b do
for j:=i to b do
n:=n+as(a,b);
writeln(n);
end.

7 条评论

  • @ 2022-03-15 20:37:57

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {
    int a,b,sum,k,ans=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
    sum=1,k=1;
    for(int j=2;j*j<=i;j++)
    if(i%j==0)sum+=j+i/j;
    for(int j=2;j*j<=sum;j++)
    if(sum%j==0)k+=sum/j+j;
    if(i==k&&i<sum)ans++;
    }
    cout<<ans;
    return 0;
    }

  • @ 2018-07-28 20:29:04

    这是正规的:
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {
    int a,b,sum,k,ans=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
    sum=1,k=1;
    for(int j=2;j*j<=i;j++)
    if(i%j==0)sum+=j+i/j;
    for(int j=2;j*j<=sum;j++)
    if(sum%j==0)k+=sum/j+j;
    if(i==k&&i<sum)ans++;
    }
    cout<<ans;
    return 0;
    }

  • @ 2018-07-28 20:28:41

    a[100]={220,1184,2620,5020,6232,10744,12285,17296,63020,66928,67095,69615,79750,100485,122265,122368,141664,142310,171856,176272,185368,196724,280540,308620,319550,356408,437456,469028,503056,522405,600392,609928,624184,635624,643336,667964,726104,802725,879712,898216,947835,998104,1077890,1077890,1154450,1280565,1392368,1511930,1798875,2082464,4238984,5459176,6329416,7677248,9363584,10254970,13921528,16137628,50997596,52695376,56055872,56512610,56924192,58580540,59497888,63560025,63717615,66595130,66854710,67729064,67738268,68891992,71015260,71241830,72958556,73032872,74055952,74386305,74769345,75171808,75226888,78088504,78447010,79324875,80422335,82633005,83135650,84521745,84591405,86158220,87998470,88144630,89477984,90437150,91996816,93837808,95629904,95791430,96304845,97041735}
    int n,m;
    scanf("%d%d",&n,&m);
    for(i=0;i<100;i++)
    if(a[i]>=n&&a[i]<=m)s++;
    printf("%d",s)

  • @ 2018-07-28 18:45:04

    还有更好的方法!试除到sqrt(n),除出一半另一半也就出来了

  • @ 2018-07-28 18:42:27

    你好!尽管我是学C++的,但我推荐一下:首先将可能用到的范围内的素数求出来,放到库里,然后再用需要的素数试除,再优化一下就可以过了

  • @ 2018-07-22 12:34:58

    不好意思,没学过**pascel**
    都不知道怎么拼

  • @ 2018-07-22 12:34:58

    不好意思,没学过**pascel**
    都不知道怎么拼

  • 1

信息

ID
1216
难度
5
分类
模拟 点击显示
标签
(无)
递交数
2685
已通过
891
通过率
33%
被复制
6
上传者