题解

167 条题解

  • -1
    @ 2015-11-08 15:52:42

    c++
    #include <iostream>
    using namespace std;
    int main()
    {
    int m,n,r,t;
    cin>>m>>n;
    int a=m;
    int b=n;
    if(m<n)
    {
    t=m;
    m=n;
    n=t;
    }
    while(r=m%n!=0)
    {
    m=n;
    n=r;
    }
    cout<<a*b/n<<endl;
    return 0;
    }

    怎么错了??

  • -1
    @ 2015-11-08 15:52:13

    #include <iostream>
    using namespace std;
    int main()
    {
    int m,n,r,t;
    cin>>m>>n;
    int a=m;
    int b=n;
    if(m<n)
    {
    t=m;
    m=n;
    n=t;
    }
    while(r=m%n!=0)
    {
    m=n;
    n=r;
    }
    cout<<a*b/n<<endl;
    return 0;
    }

  • -1
    @ 2015-10-04 16:25:36

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #include<sstream>
    long long gcd(long a,long b)
    {
    if(b==0)return a;
    gcd(b,a%b) ;
    }
    using namespace std;
    int main(){

    long long a,b;
    cin>>a>>b;
    long long w=gcd(a,b);
    cout<<(a*b/w);
    return 0;
    }

  • -1
    @ 2015-09-20 22:48:44

    高精要是用java或python太bug了,比C++的stl大法还猛maxint倍。。

    • @ 2017-08-07 13:40:18

      还有Haskell

  • -1
    @ 2015-09-04 17:14:10

    记录信息
    评测状态 Accepted
    题目 P1047 最小公倍数
    递交时间 2015-09-04 17:13:46
    代码语言 C++
    评测机 VijosEx
    消耗时间 57 ms
    消耗内存 528 KiB
    评测时间 2015-09-04 17:13:47
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 524 KiB, score = 10
    测试数据 #1: Accepted, time = 6 ms, mem = 520 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 520 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 524 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #5: Accepted, time = 5 ms, mem = 528 KiB, score = 10
    测试数据 #6: Accepted, time = 1 ms, mem = 524 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 520 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 524 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 520 KiB, score = 10
    Accepted, time = 57 ms, mem = 528 KiB, score = 100
    代码
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    using namespace std;
    char s1[110],s2[110];
    int num1[210],num2[210],num3[210],num4[210];
    int len1,len2,len3,len4;
    int ans[210];
    int ansmax;
    bool cmp()
    {
    if(len1>len2)return false;
    if(len1<len2)return true;
    for(int i=len1+1;i>=1;i--)
    {
    if(num1[i]<num2[i]) return true;
    if(num1[i]>num2[i]) return false;
    }
    return false;
    }
    int main()
    {
    scanf("%s %s",s1,s2);
    len1=strlen(s1)-1;
    len2=strlen(s2)-1;

    for(int i=len1;i>=0;i--)num1[len1-i+1]=s1[i]-'0';
    for(int i=len2;i>=0;i--)num2[len2-i+1]=s2[i]-'0';

    len1++;
    len2++;
    for(;;)
    {
    if(cmp())
    {
    int temp=len1;
    len1=len2;
    len2=temp;
    memset(num3,0,sizeof(num3));
    memcpy(num3,num2,sizeof(num2));
    memcpy(num2,num1,sizeof(num1));
    memcpy(num1,num3,sizeof(num3));
    }
    if(len2==0&&num2[1]==0)break;
    int own=0;
    int pos=len1-len2;
    for(int i=len1,j=len2;j>0;j--,i--)
    {
    if(num1[i]>num2[j])break;

    if(num1[i]<num2[j]){
    pos--;
    break;
    }
    }
    own=0;
    for(int i=1;i<=len2||own;i++)
    {
    num1[i+pos]-=num2[i]+own;
    own=0;
    if(num1[i+pos]<0)
    {
    num1[i+pos]+=10;
    own=1;
    }
    }
    for(;!num1[len1]&&len1>0;len1--);
    for(;!num2[len2]&&len2>0;len2--);
    }

    len3=len1;
    memset(num3,0,sizeof(num3));
    memcpy(num3,num1,sizeof(num1));

    len1=strlen(s1)-1;
    len2=strlen(s2)-1;

    for(int i=len1;i>=0;i--)num1[len1-i+1]=s1[i]-'0';
    for(int i=len2;i>=0;i--)num2[len2-i+1]=s2[i]-'0';

    len1++;
    len2++;

    int in=0;
    for(int i=1;i<=len1;i++)
    for(int j=1;j<=len2||in;j++)
    {
    num4[i+j-1]+=num1[i]*num2[j]+in;
    in=num4[i+j-1]/10;
    num4[i+j-1]%=10;
    len4=max(len4,i+j-1);
    }

    memcpy(num1,num4,sizeof(num4));
    memcpy(num2,num3,sizeof(num3));

    for(;;)
    {

    if(len4==0&&num1[1]==0)break;
    int own=0;
    int pos=len4-len3;
    for(int i=len4,j=len3;i>0;j--,i--)
    {
    if(num1[i]>num2[j])break;

    if(num1[i]<num2[j]){
    pos--;
    break;
    }
    }
    own=0;
    for(int i=1;i<=len3||own;i++)
    {
    num1[i+pos]-=num2[i]+own;
    own=0;
    if(num1[i+pos]<0)
    {
    num1[i+pos]+=10;
    own=1;
    }

    }
    ans[pos+1]++;
    ansmax=max(pos+1,ansmax);
    for(;!num1[len4]&&len4>0;len4--);
    for(;!num2[len3]&&len3>0;len3--);
    }
    for(int i=ansmax;i>=1;i--) printf("%d",ans[i]);
    }

  • -1
    @ 2015-07-25 19:56:42

    java就几行,哈哈哈哈哈
    import java.math.BigInteger;
    import java.util.Scanner;

    public class Main {

    public static void main(String[] args) {
    Scanner cin=new Scanner(System.in);
    BigInteger a=null,b=null,c=null;
    a=cin.nextBigInteger();
    b=cin.nextBigInteger();
    c=a.multiply(b).divide(a.gcd(b));
    System.out.println(c);

    }

    }

  • -1
    @ 2015-05-11 20:40:25

    用python直接写就可以了

    def gcd(a,b):
        if (b==0):
            return a
        else:
            return gcd(b,a%b)
    s=raw_input().split()
    a=int(s[0])
    b=int(s[1])
    print(a/gcd(a,b)*b)
    
  • -1
    @ 2015-04-16 23:17:14

    语言越来越发达!
    import java.util.*;

    import java.math.*;
    public class Main {
    public static BigInteger GCD(BigInteger a,BigInteger b)
    {

    return a.gcd(b);

    }
    public static void main(String[] args) {
    Scanner cin=new Scanner(System.in);
    BigInteger a=new BigInteger("1");
    BigInteger b=new BigInteger("1");
    BigInteger m=new BigInteger("1");
    a=cin.nextBigInteger();
    b=cin.nextBigInteger();
    m=GCD(a,b);
    System.out.println(a.multiply(b).divide(m));

    }
    }

  • -1
    @ 2015-02-01 17:00:22

    用我超长超慢的高精模板

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

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

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

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

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

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

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

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

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

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

    写快点应该可以0s...

    Code

    string a,b;

    bign A,B;
    bign S,T;
    bign D;
    int main()
    {
    cin>>a>>b;
    A=bign(a.data(),a.length());
    B=bign(b.data(),b.length());

    if(A>B) swap(A,B);
    S=A;
    T=B;

    while(A>=bign("1",1))
    {
    D=B;
    B=A;
    A=D-D/A*A;
    }

    S=S*T;
    (S/B).output();

    return 0;
    }
    不知道写递归的能不能过......

  • -1
    @ 2014-12-13 07:58:15

    超时太可怕
    做人不能太暴力
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #include<sstream>
    using namespace std;
    int main(){

    long long a,b;
    cin>>a>>b;
    long long w;
    if (a>b)
    w=a;
    else
    w=b;
    long long r=w;
    for (int i = 0; i > -1; i++)
    {
    if ((r%a==0)&&(r%b==0))
    {
    cout<<r;
    return 0;
    }
    else
    r+=w;
    }
    cout<<r;
    return 0;
    }

  • -1
    @ 2014-10-31 08:01:38

    var a,b,c:longint;
    begin
    read(a,b);
    c:=a; while not((c mod a=0)and(c mod b=0)) do inc(c);
    writeln(c);
    end.
    40 分

  • -1
    @ 2014-08-19 09:35:01

    type
    hp=record
    len:integer;
    s:array[0..200] of integer
    end;
    var
    x:array[1..2] of hp;
    g,ans,mul:hp;
    i,l,j:longint;
    st:string;
    s:array[1..2]of string;
    procedure search1(a,b:hp;var c:hp);
    var i,len:integer;
    begin
    fillchar(c,sizeof(c),0);
    if a.len>b.len then len:=a.len
    else len:=b.len;
    for i:=1 to len do begin
    inc(c.s[i],a.s[i]-b.s[i]);
    if c.s[i]<0 then begin
    inc(c.s[i],10);
    dec(c.s[i+1]);
    end;
    end;
    while(len>1) and (c.s[len]=0) do dec(len);
    c.len:=len;
    end;
    function f(const a,b:hp):integer;
    var len:integer;
    begin
    if a.len>b.len then
    len:=a.len else
    len:=b.len;
    while (len>0)and(a.s[len]=b.s[len]) do dec(len);
    if len=0 then f:=0
    else f:=a.s[len]-b.s[len]
    end;
    procedure search2(a,b:hp; var c:hp);
    var i,j,x:longint;
    begin
    fillchar(c,sizeof(c),0);
    for i:=1 to a.len do
    begin
    x:=0;
    for j:=1 to b.len do begin
    x:=x+a.s[i]*b.s[j]+c.s[i+j-1]; c.s[i+j-1]:=x mod 10; x:=x div 10;
    end;
    c.s[i+j]:=x;
    end;
    c.len:=a.len+b.len+1;
    while (c.s[c.len]=0)and(c.len>1) do dec(c.len);
    end;
    procedure search3(a,b:hp; var c,d:hp);
    var i,j,len,l:integer;
    begin
    fillchar(c,sizeof(c),0);len:=a.len;
    fillchar(d,sizeof(d),0); d.len:=1;
    for i:=len downto 1 do begin
    begin
    for l:=d.len downto 1 do
    d.s[l+1]:=d.s[l];
    d.s[1]:=0;
    inc(d.len);
    while (d.len>1)and(d.s[d.len]=0) do dec(d.len);
    end;
    d.s[1]:=a.s[i];
    while(f(d,b)>=0) do
    begin
    search1(d,b,d); inc(c.s[i]);
    end;
    end;
    while(len>1)and(c.s[len]=0) do dec(len); c.len:=len end;
    function gcd(m,n:hp):hp;
    var q,r:hp;
    begin
    if n.s[n.len]=0 then exit(m);
    search3(m,n,q,r);
    exit(gcd(n,r));
    end;
    begin
    assign(input,'password.in');reset(input);
    assign(output,'password.out');rewrite(output);
    readln(st);
    s[1]:=copy(st,1,pos(' ',st)-1);
    delete(st,1,pos(' ',st));
    s[2]:=st;
    for j:=1 to 2 do begin
    x[j].len:=length(s[j]);
    for l:=1 to x[j].len do
    x[j].s[l]:=ord(s[j][x[j].len-l+1])-48;
    end;
    g:=gcd(x[1],x[2]);
    search2(x[1],x[2],mul);
    search3(mul,g,x[1],x[2]);
    for i:=x[1].len downto 1 do write(x[1].s[i]);
    close(output);close(input);
    end.

  • -1
    @ 2014-07-14 21:59:12

    const
    maxlen=500;
    type
    hp=record
    len:integer;
    s:array[0..maxlen] of integer
    end;
    var
    x:array[1..2] of hp;
    g,ans,mul:hp; i:longint;
    procedure init;
    var
    st:string;
    s:array[1..2]of string;
    i,j:integer;
    begin
    readln(st);
    s[1]:=copy(st,1,pos(' ',st)-1);
    delete(st,1,pos(' ',st));
    s[2]:=st;
    for j:=1 to 2 do
    begin
    x[j].len:=length(s[j]);
    for i:=1 to x[j].len do
    x[j].s[i]:=ord(s[j][x[j].len-i+1])-48
    end
    end;
    procedure subtract(a,b:hp;var c:hp);
    var i,len:integer;
    begin
    fillchar(c,sizeof(c),0);
    if a.len>b.len
    then len:=a.len
    else len:=b.len;
    for i:=1 to len do
    begin
    inc(c.s[i],a.s[i]-b.s[i]);
    if c.s[i]<0 then
    begin
    inc(c.s[i],10);
    dec(c.s[i+1])
    end
    end;
    while(len>1) and (c.s[len]=0) do dec(len);
    c.len:=len
    end;
    function compare(const a,b:hp):integer;
    var len:integer;
    begin
    if a.len>b.len
    then len:=a.len
    else len:=b.len;
    while (len>0)and(a.s[len]=b.s[len]) do
    dec(len);
    if len=0
    then compare:=0
    else compare:=a.s[len]-b.s[len]
    end;
    procedure multiply10(var a:hp);
    var i:integer;
    begin
    for i:=a.len downto 1 do
    a.s[i+1]:=a.s[i];
    a.s[1]:=0; inc(a.len);
    while (a.len>1)and(a.s[a.len]=0) do
    dec(a.len);
    end;
    procedure multiply(a,b:hp; var c:hp);
    var i,j,x:longint;
    begin
    fillchar(c,sizeof(c),0);
    for i:=1 to a.len do
    begin
    x:=0;
    for j:=1 to b.len do
    begin
    x:=x+a.s[i]*b.s[j]+c.s[i+j-1];
    c.s[i+j-1]:=x mod 10;
    x:=x div 10;
    end;
    c.s[i+j]:=x
    end;
    c.len:=a.len+b.len+1;
    while (c.s[c.len]=0)and(c.len>1) do
    dec(c.len)
    end;
    procedure divide(a,b:hp; var c,d:hp);
    var i,j,len:integer;
    begin
    fillchar(c,sizeof(c),0);
    len:=a.len;
    fillchar(d,sizeof(d),0);
    d.len:=1;
    for i:=len downto 1 do
    begin
    multiply10(d);
    d.s[1]:=a.s[i];
    while(compare(d,b)>=0) do
    begin
    subtract(d,b,d);
    inc(c.s[i])
    end
    end;
    while(len>1)and(c.s[len]=0) do
    dec(len);
    c.len:=len
    end;
    function gcd(m,n:hp):hp;
    var q,r:hp;
    begin
    if n.s[n.len]=0
    then exit(m);
    divide(m,n,q,r);
    exit(gcd(n,r))
    end;
    begin
    init; g:=gcd(x[1],x[2]);
    multiply(x[1],x[2],mul);
    divide(mul,g,x[1],x[2]);
    for i:=x[1].len downto 1 do
    write(x[1].s[i]);
    writeln
    end.

    100分

    • @ 2015-10-08 15:49:56

      这是人能看懂的吗?

    • @ 2015-10-25 20:19:22

      看不懂

  • -1
    @ 2014-07-04 10:20:12

    var a,b,c,d,e:longint;
    begin
    readln(a,b);
    c:=a;
    while not((c mod a=0)and(c mod b=0)) do
    inc(c);
    writeln(c);
    end.

  • -1
    @ 2014-05-04 18:40:59

    var c,e,f,g:longint;
      a,b,d,h:qword;
    begin
    readln(e,f);
    a:=e;
    b:=f;
    d:=a-1;
    repeat
      d:=d+1;
      if (d mod a=0) and (d mod b =0) then begin
       writeln(d);
       break;
      end;
    until d=a*b;
    end.

  • -1
    @ 2014-05-04 18:40:21

    program aa;
    var temp,a,b,n,m,c,d:int64;
    begin
    readln(a,b);
    if b>a then begin
    n:=b;
    m:=a;
    c:=b;
    d:=a;
    end
    else begin
    n:=a;
    m:=b;
    c:=a;
    d:=b;
    end;
    while true do begin
    if n mod m=0 then break;

    temp:=n;
    n:=m;
    m:=temp mod m;
    end;
    writeln((c div m) *d);
    end.
    怎么也50啊

  • -1
    @ 2014-05-04 18:39:19

    var
    i,j,ans:qword;
    function try(a,b:qword):qword;
    begin
    if b=0 then try:=a
    else try:=try(b,a mod b);
    end;
    begin
    read(i,j);
    ans:=try(i,j);
    ans:=(i*j) div ans;
    writeln(ans);
    end.
    50

  • -1
    @ 2014-05-04 18:39:08

    var
    i,j,ans:qword;
    function try(a,b:qword):qword;
    begin
    if b=0 then try:=a
    else try:=try(b,a mod b);
    end;
    begin
    read(i,j);
    ans:=try(i,j);
    ans:=(i*j) div ans;
    writeln(ans);
    end.

  • -1
    @ 2014-05-04 18:38:22

    var m,n,zxgbs:integer;
    function zdgys(a,b:integer):integer;
    var
    r:integer;
    begin
    while b<>0 do
    begin
    r:=a mod b;
    a:=b;
    b:=r;
    end;
    zdgys:=a;
    end;
    begin
    read(m,n);
    zxgbs:=trunc(m*n/zdgys(m,n));
    writeln(zxgbs);
    end.

  • -1
    @ 2014-05-04 18:38:19

    var m,n,zxgbs:integer;
    function zdgys(a,b:integer):integer;
    var
    r:integer;
    begin
    while b<>0 do
    begin
    r:=a mod b;
    a:=b;
    b:=r;
    end;
    zdgys:=a;
    end;
    begin
    read(m,n);
    zxgbs:=trunc(m*n/zdgys(m,n));
    writeln(zxgbs);
    end.

信息

ID
1047
难度
8
分类
高精度 点击显示
标签
(无)
递交数
7426
已通过
784
通过率
11%
被复制
27
上传者