为何超时,求帮助。。

编译成功

foo.pas(17,16) Warning: Variable "s" does not seem to be initialized
测试数据 #0: Accepted, time = 0 ms, mem = 820 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 820 KiB, score = 10
测试数据 #2: Accepted, time = 78 ms, mem = 820 KiB, score = 10
测试数据 #3: TimeLimitExceeded, time = 1015 ms, mem = 820 KiB, score = 0
测试数据 #4: Accepted, time = 78 ms, mem = 820 KiB, score = 10
TimeLimitExceeded, time = 1171 ms, mem = 820 KiB, score = 40
代码
var
x,y,a,b,i,j,k,s:longint;
begin
read(x,y);
if x=y then write(1)
else
for i:=x to y do
for j:=2*x to y do begin
a:=i;
b:=j;
repeat
k:=b mod a;
b:=a;
a:=k;
until k=0;
if (b=x) and (i*j/b=y) then
inc(s);
end;
write(s+1);
end.

6 条评论

  • @ 2014-12-26 09:49:20

    Block code

    /*
    Author: Traveller_C
    PROG: vijos 1131
    DATE: 2014.12.26
    */

    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    const int maxn = 100005;
    const int maxm = 1000005;
    typedef long long LL;

    int x, y;
    LL sum, fac[maxn];

    LL gcd(LL x, LL y)
    {
    if (y == 0) return x;
    else return gcd(y, x % y);
    }

    int main()
    {
    scanf("%d%d", &x, &y);
    sum = x * y; int num = 0;
    for (int i = 1; i * i <= sum; i ++){
    if (sum % i == 0)
    fac[++ num] = i,
    fac[++ num] = sum / i;
    }

    int ans = 0;
    for (int i = 1; i <= num; i += 2){
    if (gcd(fac[i + 1], fac[i]) == x){
    if (fac[i] == fac[i + 1]) ans += 1;
    else ans += 2;
    }

    }

    printf("%d\n", ans);
    }

  • @ 2014-12-26 09:46:26

    Block code

    /*
    Author: Traveller_C
    PROG: vijos 1131
    DATE: 2014.12.26
    */

    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    const int maxn = 100005;
    const int maxm = 1000005;
    typedef long long LL;

    int x, y;
    LL sum, fac[maxn];

    LL gcd(LL x, LL y)
    {
    if (y == 0) return x;
    else return gcd(y, x % y);
    }

    int main()
    {
    scanf("%d%d", &x, &y);
    sum = x * y; int num = 0;
    for (int i = 1; i * i <= sum; i ++){
    if (sum % i == 0)
    fac[++ num] = i,
    fac[++ num] = sum / i;
    }

    int ans = 0;
    for (int i = 1; i <= num; i += 2){
    if (gcd(fac[i + 1], fac[i]) == x){
    if (fac[i] == fac[i + 1]) ans += 1;
    else ans += 2;
    }
    }

    printf("%d\n", ans);
    }

  • @ 2014-12-26 09:45:24

    Block Code

    /*
    Author: Traveller_C
    PROG: vijos 1131
    DATE: 2014.12.26
    */

    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    const int maxn = 100005;
    const int maxm = 1000005;
    typedef long long LL;

    int x, y;
    LL sum, fac[maxn];

    LL gcd(LL x, LL y)
    {
    if (y == 0) return x;
    else return gcd(y, x % y);
    }

    int main()
    {
    scanf("%d%d", &x, &y);
    sum = x * y; int num = 0;
    for (int i = 1; i * i <= sum; i ++){
    if (sum % i == 0)
    fac[++ num] = i,
    fac[++ num] = sum / i;
    }

    int ans = 0;
    for (int i = 1; i <= num; i += 2){
    if (gcd(fac[i + 1], fac[i]) == x){
    if (fac[i] == fac[i + 1]) ans += 1;
    else ans += 2;
    }
    }

    printf("%d\n", ans);
    }

  • @ 2014-11-22 23:55:58

    #include<stdio.h>
    int main()
    {
    int yue(int x,int y);
    int x0,y0,p,n=0;
    scanf("%d %d",&x0,&y0);
    for (p=x0;p<=y0;p++)
    if (p%x0==0 && y0%p==0)
    if (yue(p,x0*y0/p)==x0)
    n++;
    printf("%d\n",n);
    }
    int yue(int x,int y)
    {
    int i,j,k=1;
    if (x>y){i=x;j=y;}
    else {i=y;j=x;}
    k=i%j;
    while (k!=0)
    {
    i=j;j=k;
    k=i%j;
    }
    return j;
    }
    优化一下搜索方式就能过了

  • @ 2014-08-19 10:14:18

    搜索

  • @ 2014-08-18 11:11:15

    哈哈哈哈哈,人品!!!

  • 1

信息

ID
1131
难度
4
分类
其他 | 数学搜索 | 枚举 点击显示
标签
递交数
7315
已通过
2972
通过率
41%
被复制
25
上传者