193 条题解

  • -1
    @ 2015-05-26 08:32:26

    /* ***********************************************
    Author :
    Created Time :2015/5/26 8:02:37
    File Name :1.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 1<<30
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;

    bool cmp(int a,int b){
    return a>b;
    }
    int gcd(int a,int b){
    return a==0?b:(gcd(b%a,a));
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    ll y0,x0,ans;
    ll y;
    while(scanf("%I64d%I64d",&x0,&y0)!=EOF){
    ans=0;
    for(int i=x0;i<=sqrt(x0*y0);i++){
    if(y0%i==0&&i%x0==0){
    y=x0*y0/i;
    if(gcd(i,y)==x0)ans++;
    }
    }
    printf("%I64d\n",ans);
    }
    return 0;
    }

  • -1
    @ 2015-04-10 12:47:51

    #include <iostream>

    using namespace std;

    long int commonDivisor(long int a, long int b){
    int max,min;
    if(a > b){
    max = a;
    min = b;
    } else {
    max = b;
    min = a;
    }
    long int temp;
    while(max % min != 0){
    temp = max % min;
    max = min;
    min = temp;
    }
    return min;
    }

    long int commonMultiple(long int a, long int b){
    long int div= commonDivisor(a, b);
    return (a/div)*(b/div)*div;
    }

    int main(){
    long int div;
    long int mul;
    cin >> div >> mul;
    if((div > mul) || (mul%div != 0)){
    cout << 0 << endl;
    return 0;
    }
    int upBound = mul / div;
    int mount = 0;
    for(int x = 1; x <= upBound; x++)
    for(int y = 1; y <= upBound; y++)
    if(commonDivisor(div * x, div * y) == div && commonMultiple(div * x, div * y) == mul)
    mount++;
    cout << mount << endl;
    }

  • -1
    @ 2015-03-07 10:01:08

    program zhen;
    var
    i:longint;
    x,y,ans,t,a:int64;
    function gcd(a,b:int64):int64;
    begin
    if b=0 then exit(a) else exit(gcd(b,a mod b));
    end;
    procedure print(num:int64);
    begin
    writeln(num);
    halt;
    end;
    begin
    readln(x,y);
    if x=y then print(1);
    a:=x*y;
    ans:=0;
    for i:=1 to trunc(sqrt(a)) do
    if a mod i=0 then
    begin
    t:=gcd(i,a div i);
    if (t=x) and (a div t=y) then inc(ans);
    end;
    print(ans*2);
    end.
    简单数学知识,a*b=lcm(a,b)*gcd(a,b),既AB的积等于他们的最大公约数和最小公倍数之积,然后枚举下就可以了

  • -1
    @ 2015-02-03 19:46:15

    渣渣也来水一发,沾沾楼下各位大神的仙气!

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    Accepted, time = 0 ms, mem = 556 KiB, score = 50

    代码
    #include <iostream>
    #include<cmath>
    using namespace std;
    int gcd(int m, int n)
    {
    while (m != n)
    {
    if (m>n) m -= n;
    else n -= m;
    }
    return m;
    }

    int main()
    {
    long long x, y, hahaha = 0, hahahaha = 0, ha, haha;
    cin >> x >> y;
    ha = x * y;
    hahahaha = sqrt(double(y/x));
    for (int i = 1; i <= hahahaha; i++)
    {
    haha=i*x;
    if (y % haha == 0)
    if(gcd(haha,ha/haha)==x)
    hahaha++;
    }

    cout << 2 * hahaha << endl;
    return 0;
    }

  • -2
    @ 2017-08-23 10:33:32
    //分析:
    //要点:P*Q = x0*y0,即两个数的最大公约数和最小公倍数之积等于这两个数的积,然后根据这一点分析符合要求的数。我们先求出x0*y0,然后枚举P从i=2到i=根号x0*y0,只要满足x0*y0是i的倍数,且P,Q均为x0的倍数,且y0为x0,y0的倍数,并且还要满足P,Q的最小公约数是x0,因为15,12和12,15都满足,所以最后将答案*2即可。
    #include<iostream>
    #include<math.h>
    using namespace std;
    
    int x, y;
    
    void swap(int &a, int &b) {//交换a,b
        int temp = a;
        a = b;
        b = temp;
    }
    int gcd(int a, int b) {//求a,b的最大公约数
        if (a < b) swap(a, b);
        int r = a%b;
        while (r) {
            a = b;
            b = r;
            r = a%b;
        }
        return b;
    }
    int main() {
        cin >> x >> y;
        long long a = x*y;
        int ans = 0;
        for (int i = 2; i <= sqrt(a)+1; i++) {
            if (a%i == 0 && i%x == 0 && y%i == 0 && (a / i) % x == 0 && y % (a / i) == 0) {
                int m = i, n = a / i;
                if (gcd(n, m) == x) ans++;
            }
        }
        cout << ans*2 << endl;
        return 0;
    }
    
  • -2
    @ 2017-08-20 00:10:04

    终于遇到一个不硬的柿子 T_T

    #include <stdio.h>

    int zuida(long x,long y,long z)
    {
    long temp;
    if( x%z!=0 || y%z!=0 ) return 0;
    while(x!=y)
    {
    if(x>y) {temp=x;x=y;y=temp;}
    y=y-x;
    }
    if(y!=z) return 0;
    else return 1;
    }

    int main()
    {
    long i,j,a,b,sum=0;
    scanf("%ld %ld",&a,&b);

    for(i=a;i<=b;i++)
    for(j=a;j<=b;j++)
    {
    if(i*j != a*b) continue;
    if( zuida(i,j,a) )
    sum++;
    }
    printf("%ld",sum);
    return 0;
    }

  • -2
    @ 2017-08-15 21:16:29
    import re
    import sys
    
    def readln():
        return map(int, input().split())
    
    def read():
        s = input()
        k = []
        r = []
        k = re.split(' ',s)
        for i in k:
            r.append(int(i))
        return r
    
    def write(e,ed):
        for i in e:
            print(i,end=ed)
        print()
    
    def gcd(a,b):
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    
    a,b = readln()
    if a<b:
        a,b = b,a
    f = gcd(a,b)
    if f != b:
        print(0)
    else:
        a //= f
        ans = 0
        for i in range(1,a+1):
            if a % i == 0:
                if a//i<i:
                    r=i
                    t=a//i
                else:
                    r=a//i
                    t=i
                
                if gcd(r,t) == 1:
                    ans+=1
                    #print(i*f,a//i*f)
        print(ans)
    
    

    啦啦啦

  • -2
    @ 2017-05-08 09:03:56
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <iomanip>
    #include <cstdlib>
    using namespace std;
    
    int n,m;
    
    int gcd(int a,int b)
    {
        return b==0?a:gcd(b,a%b);
    }
    
    int main()
    {
        int ans=0;
        cin>>n>>m;
        int a=n*m;
        for(int i=2;i<=a;i++)
        {
            if(a%i!=0)
                continue;
            else
            {
                int j=a/i;
                if(gcd(i,j)==n)
                    ans++;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
         
    
  • -2
    @ 2017-04-14 19:28:41

    这题主要是对于p,q两个数的查找。
    (定义:x0=x1; y0=y1)
    最先想到的是把每种可能全找出来,统计结果。
    如果我们需要找p,q两个数,为了优化时间,只需从1..x2/x1查找即可(也就是同除p,q两个数的最大公约数)。
    因为 m最坏情况是1000000,可以在一秒内通过
    所以 线性查找可以解决。

    几个需要注意的点:
    1.查找是***必须***先判断x2 mod x1(也就是c++中的x2%x1)的结果是否不为0,如不为0,则直接输出0,即没有符合条件的x2,x1;
    2.需要判断x2,x1是否有公约数。

    人民喜闻乐见的代码:

    uses math;
    var x1,x2,p,i,j,ans:longint;
    
    function pd(x,y:longint):byte;
    var m,i:longint;
        begin
            m:=min(x,y);
            pd:=0;
            for i:=2 to m do
                if (x mod i=0) and (y mod i=0) then begin pd:=1; exit; end;
        end;
    
        begin
            readln(x1,x2);
            if x2 mod x1<>0 then begin write(0); exit; end else
                begin
                    p:=x2 div x1;
                    i:=1;
                    while i<=p do
                        begin
                            if p mod i=0 then 
                                begin 
                                    j:=p div i; 
                                    if pd(i,j)=0 then inc(ans);
                                end;
                            inc(i);
                        end;
                end;
            write(ans);
        end.                    
    

    ps 欢迎指教

  • -2
    @ 2016-08-15 17:45:55
    int gcd(int a, int b)
    {
        if(a < b)
        {
            swap(a, b);   
        }
    
        if(b == 0)
        {
            return a;
        }
    
        if((a & 0x1) == 0 && (b & 0x1) == 0) 
        {
            return 2 * gcd(a >> 1, b >> 1);
        }
    
        if((a & 0x1) == 0 && (b & 0x1) != 0) 
        {
            return gcd(a >> 1, b);
        }
    
        if((a & 0x1) != 0 && (b & 0x1) == 0) 
        {
            return gcd(a, b >> 1);
        }
    
        if((a & 0x1) != 0 && (b & 0x1) != 0) 
        {
            return gcd((a - b) >> 1, b);
        }
    }
    

    二进制版gcd,加不加都是0ms

  • -2
    @ 2016-08-10 11:44:40

    数据真是高端大气上档次。。
    c++
    #include <cstdio>
    int n,m,x,p,q,ans=0,t=2;
    int gcd(int x,int y)
    {
    if (y==0) return x;
    else return gcd(y,x%y);
    }
    int main()
    {
    scanf("%d%d",&n,&m);
    p=n*m;q=n;
    while(q<=m)
    {
    x=p/q;
    if(x*q==p)
    if(gcd(x,q)==n) ans++;
    q=n*t++;
    }
    printf("%d",ans);
    }

    这样的程序都能0ms,也是醉了

  • -2
    @ 2016-07-29 17:41:26
    #include <stdio.h>
    #include <stdlib.h>
    
    int corr(int x0,int y0,int p,int q)
    {
        int i=1,j;
        j=i*p;
        while(j%q!=0)
        {
            i++;
            j=i*p;
        }
        if(j!=y0)
            return 0;
        return 1;
    }
    int main()
    {
        int x0,y0,p,q,sum=0,ji;
        scanf("%d%d",&x0,&y0);
        ji=x0*y0;
        for(p=x0;p<=y0;p++)
        {
            q=ji/p;
            if(corr(x0,y0,p,q))
                sum++;
        }
        printf("%d",sum);
        return 0;
    }
    
  • -2
    @ 2016-07-29 06:37:22
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    
    using namespace std;
    
    int n,m,a,b,k;
    
    int gcd(int a,int b)
    {
        return b==0 ? a:gcd(b,a%b);
    }
    
    int main()
    {
        cin>>n>>m;
        k=n*m;
        a=n;
        int ans=0;
        int kk=2;
        while(a<=m)
        {
            b=k/a;
            if(a*b==k)
                if(gcd(a,b)==n)
                {
                    ans++;
                    //cout<<a<<endl;
                }
            a=n*kk;
            kk++;
        }
        cout<<ans;
        return 0;
    }
    

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

信息

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