193 条题解

  • 0
    @ 2014-12-29 19:08:55

    #include<iostream>
    using namespace std;
    int find(int a,int b)
    {
    int c;
    if(a%b==0)
    return b;
    else
    {
    c=b;
    b=a%b;
    a=c;
    find(a,b);

    }
    }
    int main()
    {
    int x0,y0,a[10000]={0},s=1,t=1,n=0,tot=0,m,mm,nn;
    cin>>x0>>y0;
    if(x0>y0)
    {
    cout<<"0";
    return 0;
    }
    m=x0*y0;
    a[s]=x0;
    while(a[s]<=y0)
    {
    if(y0%a[s]==0)
    {
    a[s]=x0*t;
    s=s+1;
    }
    t=t+1;
    a[s]=x0*t;
    }
    for(int i=1;i<=10000;++i)
    {
    if(a[i]!=0)
    n=n+1;
    if(a[i]==0)
    break;
    }
    for(int i=1;i<n;++i)
    {
    for(int k=1;k<n;++k)
    {
    if(a[i]!=a[k])
    {
    mm=find(a[i],a[k]);
    nn=a[i]*a[k]/mm;
    if(mm==x0&&nn==y0)
    tot=tot+1;
    }
    }
    }
    cout<<tot;
    return 0;
    }

  • 0
    @ 2014-11-05 21:50:06

    var i,j,k,gcd,gbs,t,tot,zs:longint;
    begin
    readln(gcd,gbs);
    if gbs mod gcd<>0 then begin
    writeln(0);haltend;
    t:=gbs div gcd;
    i:=1;
    while t>1 dobegin
    inc(i);
    if t modi=0 then
    begin
    inc(tot);
    while tmod i=0 do
    t:=t divi;
    endend;

    zs:=trunc(exp(ln(2)*tot));
    writeln(zs);
    end.

    编译成功
    测试数据 #0: Accepted, time = 0 ms, mem = 728 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 728 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 728 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    Accepted, time = 0 ms, mem = 732 KiB, score = 50

    • @ 2014-11-05 21:50:55

      我去掉了一些空格,防小人不防君子

    • @ 2019-04-06 11:43:43

      @
      yingjiangyu
      : 你说了去空格就没用了嘛,先等他们运行错误自己找嘛(手动滑稽)

  • 0
    @ 2014-11-01 21:49:40

    代码有点丑。。。见谅!
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    typedef long long LOL;
    long long int x,y,p,q,ans,temp;
    LOL zuidagongyueshu(LOL a,LOL b)
    {
    if(a<b) swap(a,b);
    if(b==0) return a;
    else return zuidagongyueshu(b,a%b);
    }
    int main()
    {
    scanf("%d%d",&x,&y);
    p=2;
    q=3;
    while(p<=y)
    {
    if((x*y)%p==0)
    {
    if((x*y)/p<=y)
    {q=(x*y)/p;
    temp=zuidagongyueshu(p,q);
    if(temp==x&&p/temp*q==y) ans++;}
    }
    p++;
    }
    printf("%d",ans);
    return 0;
    }

  • 0
    @ 2014-11-01 08:32:40

    编译成功

    foo.pas(6,8) Warning: Variable "i" does not seem to be initialized
    foo.pas(21,52) 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 = 816 KiB, score = 10

    测试数据 #2: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #3: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 820 KiB, score = 10

    Accepted, time = 45 ms, mem = 820 KiB, score = 50

    代码
    var
    x1,x2,i,j,s,y,r,a,b:int64;
    begin
    readln(x1,x2);
    repeat
    i:=i+x1;
    j:=0;
    repeat
    j:=j+x1;
    a:=j;
    b:=i;
    repeat
    if a<b then begin r:=a; a:=b; b:=r; end; a:=a-b; until a=0; if (i*j div x1 =x2) and (b=x1 ) then s:=s+1; until j>=x2;
    until i>=x2;
    write(s);
    end.

  • 0
    @ 2014-11-01 08:32:35

    编译成功

    foo.pas(6,8) Warning: Variable "i" does not seem to be initialized
    foo.pas(21,52) 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 = 816 KiB, score = 10

    测试数据 #2: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #3: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 820 KiB, score = 10

    Accepted, time = 45 ms, mem = 820 KiB, score = 50

    代码
    var
    x1,x2,i,j,s,y,r,a,b:int64;
    begin
    readln(x1,x2);
    repeat
    i:=i+x1;
    j:=0;
    repeat
    j:=j+x1;
    a:=j;
    b:=i;
    repeat
    if a<b then begin r:=a; a:=b; b:=r; end; a:=a-b; until a=0; if (i*j div x1 =x2) and (b=x1 ) then s:=s+1; until j>=x2;
    until i>=x2;
    write(s);
    end.

  • 0
    @ 2014-11-01 08:32:30

    编译成功

    foo.pas(6,8) Warning: Variable "i" does not seem to be initialized
    foo.pas(21,52) 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 = 816 KiB, score = 10

    测试数据 #2: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #3: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 820 KiB, score = 10

    Accepted, time = 45 ms, mem = 820 KiB, score = 50

    代码
    var
    x1,x2,i,j,s,y,r,a,b:int64;
    begin
    readln(x1,x2);
    repeat
    i:=i+x1;
    j:=0;
    repeat
    j:=j+x1;
    a:=j;
    b:=i;
    repeat
    if a<b then begin r:=a; a:=b; b:=r; end; a:=a-b; until a=0; if (i*j div x1 =x2) and (b=x1 ) then s:=s+1; until j>=x2;
    until i>=x2;
    write(s);
    end.

  • 0
    @ 2014-11-01 08:32:16

    编译成功

    foo.pas(6,8) Warning: Variable "i" does not seem to be initialized
    foo.pas(21,52) 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 = 816 KiB, score = 10

    测试数据 #2: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #3: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 820 KiB, score = 10

    Accepted, time = 45 ms, mem = 820 KiB, score = 50

    代码
    var
    x1,x2,i,j,s,y,r,a,b:int64;
    begin
    readln(x1,x2);
    repeat
    i:=i+x1;
    j:=0;
    repeat
    j:=j+x1;
    a:=j;
    b:=i;
    repeat
    if a<b then begin r:=a; a:=b; b:=r; end; a:=a-b; until a=0; if (i*j div x1 =x2) and (b=x1 ) then s:=s+1; until j>=x2;
    until i>=x2;
    write(s);
    end.

  • 0
    @ 2014-10-04 14:23:57

    编译成功

    foo.pas(6,8) Warning: Variable "i" does not seem to be initialized
    foo.pas(21,52) 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 = 816 KiB, score = 10

    测试数据 #2: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #3: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 820 KiB, score = 10

    Accepted, time = 45 ms, mem = 820 KiB, score = 50

    代码
    var
    x1,x2,i,j,s,y,r,a,b:int64;
    begin
    readln(x1,x2);
    repeat
    i:=i+x1;
    j:=0;
    repeat
    j:=j+x1;
    a:=j;
    b:=i;
    repeat
    if a<b then
    begin
    r:=a;
    a:=b;
    b:=r;
    end;
    a:=a-b;
    until a=0;
    if (i*j div x1 =x2) and (b=x1 ) then s:=s+1;
    until j>=x2;
    until i>=x2;
    write(s);
    end.

  • 0
    @ 2014-10-03 20:50:15

    其实就是杨辉三角一行的求和2^n 注意两数互质
    var x0,y0,a:int64;
    rec:array[1..100000]of integer;
    ii,sum,i,n:longint;
    procedure factor;
    begin
    n:=2;
    ii:=0;
    while n<=a do
    begin
    if a mod n=0 then
    begin
    while a mod n=0 do
    a:=a div n;
    inc(ii);
    rec[ii]:=n;
    end;
    inc(n);
    end;
    end;

    begin
    read(x0,y0);
    if y0 mod x0<>0 then begin write('0');halt;end;
    a:=y0 div x0;
    factor;
    sum:=1;
    for i:=1 to ii do
    sum:=sum*2;
    write(sum);
    end.

  • 0
    @ 2014-08-29 20:50:37

    测试数据 #0: Accepted, time = 15 ms, mem = 272 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 276 KiB, score = 10

    测试数据 #2: Accepted, time = 15 ms, mem = 276 KiB, score = 10

    测试数据 #3: Accepted, time = 15 ms, mem = 276 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 276 KiB, score = 10

  • 0
    @ 2014-08-24 13:26:32

    #include<iostream>
    using namespace std;
    int a[10005];
    /*思路:因为x0是最大公约数,y0是最小公倍数,所以,假设x,y 是一组满足条件的数,
    那么有 x%x0 == 0 y%x0 == 0 x*y = x0*y0所以,我们先找到所有x0到
    yo范围内的x0的倍数,这个倍数还要满足y0%x == 0 所以 我们用一个数组存
    下这些数 比如 3- 60 就是 3 6 12 15 30 60 6个数 满足x%x0==0 y0%x==0
    然后枚举这里面的每两个数的公约数,当然前提是x*y = x0*y0*/
    int zzxc(int a,int b)//辗转相除法
    {
    int t;
    while(b>0)
    {
    t=a%b;
    a=b;
    b=t;
    }
    return a;
    }
    int main()
    {
    int x,y,i,l=0,j,s=0;
    cin>>x>>y;
    for(i=x;i<=y;i+=x)
    if(y%i==0)
    a[l++]=i;
    for(i=0;i<l;i++)
    for(j=i+1;j<l;j++)
    if(a[i]*a[j]==x*y&&zzxc(a[i],a[j])==x)
    s+=2;
    cout<<s<<endl;
    return 0;
    }

  • 0
    @ 2014-08-18 11:26:48

    24K纯水啊。。。
    #include <iostream>
    #include <algorithm>
    using namespace std;

    long long gcd(long long a,long long b)
    {
    if(a<b) swap(a,b);
    return (b==0)?a:gcd(b,a%b);
    }
    int main()
    {
    long long x0,y0; cin>>x0>>y0;
    if(x0==y0) { cout<<1<<endl;return 0; }
    long long t=x0*y0;
    long long ans=0;
    long long a,b,gab;
    for(long long i=1;i*i<=t;++i)
    {
    if(!(t%i))
    {
    a=i;b=t/i;
    // cout<<a<<" "<<b<<endl;
    gab=gcd(a,b);
    if(gab==x0 && a/gab*b==y0) ans++;
    }
    }

    cout<<ans*2<<endl;
    }

  • 0
    @ 2014-07-15 23:46:57

    编译成功

    Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
    Copyright (c) 1993-2014 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    foo.pas(22,47) Warning: Variable "ans" does not seem to be initialized
    Linking foo.exe
    27 lines compiled, 0.1 sec , 28176 bytes code, 1628 bytes data
    1 warning(s) issued
    测试数据 #0: Accepted, time = 0 ms, mem = 740 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 740 KiB, score = 10
    测试数据 #2: Accepted, time = 125 ms, mem = 740 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 740 KiB, score = 10
    测试数据 #4: Accepted, time = 109 ms, mem = 744 KiB, score = 10
    Accepted, time = 234 ms, mem = 744 KiB, score = 50
    var x,y,p,q,ans,s:longint;
    function gcd(a,b:longint):longint;
    begin
    if b=0 then exit(a) else gcd:=gcd(b,a mod b);
    end;

    function acm(a,b,w:longint):longint;
    begin
    acm:=a*b div w;
    end;

    BEGIN
    readln(x,y);
    if y mod x<>0 then begin
    writeln(0);
    halt;
    end else begin
    for p:=x to y do
    for q:=x to y do
    begin
    s:=gcd(p,q);
    if (s=x) and (acm(p,q,s)=y) then inc(ans);
    end;
    writeln(ans);
    end;
    end.

  • 0
    @ 2014-04-06 15:40:05

    #include <iostream>
    using namespace std;
    int n,m;
    int main()
    {
    int i,j,k,l,q,w,e;
    cin >>n>>m;
    if ((n==0)||(m==0)||(m%n!=0)||(n>m)) {cout <<0;return 0;}
    if (n==m) {cout <<1;return 0;}
    m/=n;w=0;
    for (i=1;i*i<=m;i++) if (m%i==0)
    {
    k=i;l=m/i;e=0;
    for (j=2;j<=k;j++) if ((k%j==0)&&(l%j==0)) {e=1;break;}
    if (e==1) continue;w+=2;
    }
    cout <<w<<endl;
    }

  • 0
    @ 2014-02-19 22:18:43

    内存开long long就莫名其妙的过了,说好的O(100000*1000000)呢?
    测试数据 #0: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #2: Accepted, time = 62 ms, mem = 268 KiB, score = 10
    测试数据 #3: Accepted, time = 982 ms, mem = 272 KiB, score = 10
    测试数据 #4: Accepted, time = 31 ms, mem = 268 KiB, score = 10
    Accepted, time = 1090 ms, mem = 272 KiB, score = 50
    代码
    //暴力搜索
    #include <iostream>

    #include <stdio.h>
    using namespace std;
    long long x0,y0,ans;
    int d,p,Q; //P与Q的最大公因数
    inline void init(){
    scanf("%d %d",&x0,&y0);
    }
    inline int gcd(int p,int q){
    int s=1;
    if(p<q)swap(p,q);
    while(s!=0){s=p%q;p=q;;q=s;}//辗转相除法找出最大公因数
    return p;
    }
    inline void dfs(){ //暴搜求出P,Q的个数
    for(p=x0;p<=y0;p++) //使他们之积小于最小公倍数--剪枝
    for(Q=x0;Q<=y0;Q++){
    d=gcd(p,Q);
    if(d==x0 && p*Q/d==y0)ans++; //判断是否符合条件
    }
    printf("%d\n",ans);
    }
    int main(){
    init();
    dfs();
    return 0;
    }

    • @ 2014-08-04 10:49:05

      O(100000*1000000) = O(1)

  • 0
    @ 2013-12-14 14:26:46

    include<iostream>
    using namespace std;
    int gys(int x,int y){
    if(x>y)swap(x,y);
    if(x==0)return y;
    else return gys(x,y%x);
    }
    int gbs(int x,int y){
    if(x>y)swap(x,y);
    int t=1;
    while(y*t%x!=0)t++;
    return t*y;
    }
    int main(){
    int x,y,count=0,i;
    long long s;
    cin>>x>>y;
    s=x*y;
    for(i=x;i<=y;i++){
    if(gys(i,s/i)==x && gbs(i,s/i)==y){
    count++;
    }
    }
    cout<<count<<endl;
    return 0;
    }

  • 0
    @ 2013-11-09 12:35:41

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 464 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 464 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 464 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 472 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 464 KiB, score = 10
    Accepted, time = 0 ms, mem = 472 KiB, score = 50
    代码
    #include<iostream>
    using namespace std;

    int gys(int x,int y){
    if(x>y)swap(x,y);
    if(x==0)return y;
    else return gys(x,y%x);
    }

    int gbs(int x,int y){
    if(x>y)swap(x,y);
    int t=1;
    while(y*t%x!=0)t++;
    return t*y;
    }

    int main(){
    int x,y,count=0,i;
    long long s;
    cin>>x>>y;
    s=x*y;
    for(i=x;i<=y;i++){
    if(gys(i,s/i)==x && gbs(i,s/i)==y){
    count++;
    }
    }
    cout<<count<<endl;
    return 0;
    }

  • 0
    @ 2013-10-03 19:54:26

    这道题的数学方法想了很久,自认为应该是正解了。
    看到有多程序贴着,但觉得不少都是骗来的。因为数据特别水。
    如果讲得不对,或是不清楚,欢迎大家指出来。QQ841249284
    下面就发表一些拙见:
    就样例而言:3 60
    首先当然要判断 60 mod 3是否为0,若不为0,则立即halt;
    k:=60 div 3;//=20
    然后把k分解质因数,得到:
    2 5
    2 1
    x,y分别是指两个待求的数
    显然这两个2,要不全部都给x,要不都是y.否则如果分别给x,y,那么最大公约数就变成6了,所以就有2种方案
    剩下的5,也是这样,可以x,y分别放,又是2中可能。所以答案就是2*2=4。
    按照这种思想,就可以将k分解质因数,然后算出k有几个不同的因数,然后答案就为2^k.

    DXE—IOU             SYF

  • 0
    @ 2013-06-07 21:27:36

    没发现m%n!=0.......
    还是水过了。。
    VijosEx via JudgeDaemon2/13.6.5.0 via libjudge
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 436 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 444 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 444 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 444 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 436 KiB, score = 10
    Accepted, time = 0 ms, mem = 444 KiB, score = 50
    #include <cstdio>
    #include <cmath>

    using namespace std;

    int n,m;

    int gcd(int a,int b){
    if (a%b==0) return b;
    return gcd(b,a%b);
    }

    int main(){
    scanf("%d%d",&n,&m);
    if (m%n) {
    printf("0\n");
    return 0;
    }
    int x=m/n;
    int ans=0;
    for (int i=0;i++<int(sqrt(x));){
    if (x%i==0){
    if (gcd(x/i,i)==1){
    if (x/i!=i) ans+=2; else ans+=1;
    }
    }
    }
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2012-11-05 11:08:24

    program pxxx;

    var x,y,i,o:integer;

    begin

    readln(x,y);

    if y mod x0 then

    begin

      writeln(0);

      halt;

    end;

    o:=0;

    y:=y div x;

    for i:=2 to (y-1) do

    if y mod i=0 then

    begin

      inc(o);

      while y mod i =0 do y:=y div i;

    end;

    writeln(o*(o-1)+2);

    end.

    直接ac

最小公倍数和最大公约数问题

信息

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