题解

103 条题解

  • 0
    @ 2014-12-07 16:39:50

    又快又简单
    【Pascal Code】
    var
    a,b,c,d:qword;
    n,i:longint;
    begin
    readln(n);
    readln(a,b);
    for i:=2 to n do
    begin
    readln(c,d);
    while b mod c<>d do b:=a+b;
    a:=a*c;
    end;
    writeln(b);
    end.

  • 0
    @ 2014-11-07 10:27:30

    要注意ans 和 add的初值。。
    ans=b 因为可能出现ans=b2(moda2);
    add=a;
    #include <stdio.h>
    #include <iostream>
    using namespace std;

    int a,b,n;
    long long ans,gcd;

    int main(){
    cin>>n;
    int i,j;
    cin>>a>>b;
    ans=b;
    gcd=a;
    for(i=2;i<=n;++i){
    cin>>a>>b;
    while(ans%a!=b)ans+=gcd;
    gcd*=a;
    }
    cout<<ans;
    }

  • 0
    @ 2014-07-31 22:22:08

    记录信息
    评测状态 Accepted
    题目 P1164 曹冲养猪
    递交时间 2014-07-31 22:20:24
    代码语言 C++
    评测机 VijosEx
    消耗时间 15 ms
    消耗内存 272 KiB
    评测时间 2014-07-31 22:20:28
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    Accepted, time = 15 ms, mem = 272 KiB, score = 100
    代码
    #include <iostream>
    #include <cstdlib>

    using namespace std;

    int main()
    {
    long long num = 0;
    int a = 0, b = 0, gcd = 0;

    cin >> a;
    cin >> a >> b;
    gcd = a;
    num = b;

    while(!(cin >> a >> b).fail())
    {
    while(num % a != b)
    {
    num += gcd;
    }
    gcd *= a;
    }
    cout << num << endl;
    return 0;
    }

    好简单~~~
    第一次想烦了~~~

  • 0
    @ 2014-07-09 00:12:38

    国产的定理很有用...
    var a,b,e:array[1..10] of int64;
    n,i:longint;
    m,ans,p,q:int64;
    procedure sol(a,b:int64;var x,y:int64);
    begin
    if b=0 then begin
    x:=a;
    y:=0;
    end else begin
    sol(b,a mod b,y,x);
    y:=y-x*(a div b);
    end;
    end;
    begin
    readln(n);
    m:=1;
    for i:=1 to n do begin
    readln(a[i],b[i]);
    m:=m*a[i];
    end;
    for i:=1 to n do e[i]:=m div a[i];
    for i:=1 to n do begin
    sol(e[i],a[i],p,q);
    ans:=ans+e[i]*p*b[i];
    if ans<0 then ans:=m-(-ans mod m) else ans:=ans mod m;
    end;
    writeln(ans);
    end.

  • 0
    @ 2014-05-04 18:58:52

    var n,i:longint;
    x,y,a,b,c,d:int64;
    procedure shu(o,p,q:int64;var u,v:int64);
    var e,f,g,h:int64;
    begin
    e:=p div o;f:=q div o;
    p:=p mod o;q:=q mod o;
    if (p=0)and(q=0) then begin u:=e;v:=f;end
    else begin
    if p=1 then begin g:=o;h:=-q;if h<0 then h:=o-q;end else shu(p,o,-q,g,h);
    u:=e*g+p*g div o;v:=e*h+(p*h+q) div o+f;
    end;
    v:=v mod u;
    if v<0 then v:=u+v;
    end;
    begin
    readln(n);
    readln(x,a);
    for i:=1 to n-1 do
    begin
    readln(y,b);
    if x=y then continue;
    if x>y then begin shu(y,x,a-b,c,d);a:=d*y+b;x:=c*y;end
    else begin shu(x,y,b-a,c,d);a:=d*x+a;x:=c*x;end;
    a:=a mod x;
    if a<0 then a:=x+a;
    end;
    writeln(a);
    end.

  • 0
    @ 2013-10-24 18:37:39

    中国剩余定理和Ex_Euclid又不难写为何不用
    const
    mn=11;
    var
    ni,mi:Array[0..mn]of int64;
    i,j,k:longint;
    ans,n,mk,m,x,y:int64;
    procedure gcd(a,b:int64);
    var
    t:int64;
    begin
    if b=0 then
    begin
    x:=1;
    y:=0;
    end
    else
    begin
    gcd(b,a mod b);
    t:=x;
    x:=y;
    y:=t-(a div b)*y;
    end;
    end;
    begin
    fillchar(ni,sizeof(ni),0);
    fillchar(mi,sizeof(mi),0);
    read(j);
    n:=int64(j);
    for i:=1 to n do
    begin
    read(j,k);
    ni[i]:=int64(j);
    mi[i]:=int64(k);
    end;
    ans:=0;
    m:=1;
    for i:=1 to n do
    m:=m*ni[i];
    for i:=1 to n do
    begin
    mk:=m div ni[i];
    gcd(mk,ni[i]);
    ans:=(ans+(mk*x) mod m*mi[i] mod m)mod m;
    end;
    if ans<0 then
    inc(ans,m);
    writeln(ans);
    end.

  • 0
    @ 2013-07-25 17:02:24

    #include<iostream>
    using namespace std;
    int main()
    {
    int n;
    cin>>n;
    int a[10],b[10];
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i];
    int max;
    for(int k=1;k<n;k++)
    {
    if(a[k]>a[k-1])
    max=a[k];
    }
    int h;

    for(h=max;h<100000;h++)
    {
    int j;
    for(j=0;j<n;j++)
    {
    if(h%a[j]!=b[j])
    break;
    }
    if(j>=n)
    break;
    }
    cout<<h;
    return 0;
    }

  • 0
    @ 2012-07-22 10:59:23

    中国剩余定理,我说一下我的做法:

    设定一个数据 3 2

    5 3

    7 4

    设X=3n+2,那么当n=2时 X mod 5=3,X=8

    所以X=8符合除3余2 除5余3

    但最后一个条件是用7除余4.8不满足这个条件.我们要在8的基础上得到一个数,使之同时满足三个条件.

    为此,我们想到,可以使新数等于8与3和5的一个倍数的和.因为8加上3与5的任何整数倍所得之和除以3仍然余2,除以5仍然余3.

    于是我们让新数为8+15n,(15是3和5的最小公倍数,8+15m),分别把n=1,2...代进去试验.当试到n=3时,得到8+15n=53,53除以7恰好余4,因而53合乎题目要求.

    具体实现就是要枚举n

    来源于http://www.shuxuepeiyou.com/newsshow.asp?id=1828 前半部分

    连我这种菜鸟都看得懂,你们也肯定看得懂~!!!

  • 0
    @ 2009-11-06 15:29:01

    内牛满面。。

    第一遍。

    没用qword

    第二遍

    把i也定成qword,..

    第三遍

    AC。

    中国模拟定理!

    让我感动的一题!

  • 0
    @ 2009-11-06 10:12:15

    中国剩余定理!

    让我感动的一题!

  • 0
    @ 2009-11-01 11:05:52

    严格按照中国剩余定理做的, 没有枚举``

    ---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|-

    var

    i,j,k,n,js1:longint;

    s,pj:qword;

    a,b,suma,sumb,b1,a1:array[1..1000] of int64;

    procedure js(x,y:int64);

    begin

    a1[1]:=x mod y; b1[1]:=y; inc(k);

    while (a1[k]1) and (b1[k]1) do

    begin

    inc(k);

    if odd(k) then

    begin

    a1[k]:= a1[k-1] mod b1[k-1];

    b1[k]:=b1[k-1];

    end

    else

    begin

    a1[k]:=a1[k-1];

    b1[k]:=b1[k-1] mod a1[k-1];

    end;

    end;

    if a1[k]=1 then

    begin

    suma[k]:=1;

    sumb[k]:=0;

    end

    else if b1[k] =1 then

    begin

    sumb[k]:=a1[k]-1;

    suma[k]:=1;

    end;

    for j:= k-1 downto 1 do

    begin

    if odd(j) then

    begin

    sumb[j]:=sumb[j+1];

    suma[j]:=(sumb[j]*b1[j]+1) div a1[j];

    end

    else

    begin

    suma[j]:=suma[j+1];

    sumb[j]:=(a1[j]*suma[j+1]-1) div b1[j];

    end;

    end;

    js1:=suma[1];

    end;

    //---|---|---|---|---|---|---|---|---|---|--

    begin

    read(n);

    s:=1;

    pj:=0;

    for i:= 1 to n do

    begin

    read(a[i],b[i]);

    s:=s*a[i];

    end;

    for i:= 1 to n do

    begin

    k:=0;

    js(s div a[i],a[i]);

    pj:=(pj+b[i]*js1*(s div a[i])) mod s;

    end;

    write(pj mod s);

    end.

  • 0
    @ 2009-10-31 09:58:14

    无语了

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:运行时错误...|错误号: -1073741676

    ├ 测试数据 03:运行时错误...|错误号: -1073741676

    ├ 测试数据 04:运行时错误...|错误号: -1073741676

    ├ 测试数据 05:运行时错误...|错误号: -1073741676

    ├ 测试数据 06:运行时错误...|错误号: -1073741676

    ├ 测试数据 07:运行时错误...|错误号: -1073741676

    ├ 测试数据 08:运行时错误...|错误号: -1073741676

    ├ 测试数据 09:运行时错误...|错误号: -1073741676

    ├ 测试数据 10:运行时错误...|错误号: -1073741676

  • 0
    @ 2009-10-26 21:37:15

    O(∩_∩)O哈哈~

    第1600个AC!!

    O(∩_∩)O哈哈~

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-10-22 21:06:14

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    庆祝一颗星 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

  • 0
    @ 2009-10-05 14:24:20

    水题。。。

    for (i=1;i>a>>b;while(t%a!=b)t+=s;s*=a;}

    程序超级简单

    ac了

  • 0
    @ 2009-10-03 15:10:48

    全选!!!!!!!!!!!!!!!!!!

    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

    qtn=>pig

  • 0
    @ 2009-09-30 20:11:33

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    本人一介初中生,一看便知这是一个不定方程,可以用变量分离与辗转相除(我不懂同余方程)

    var n,i:longint;

    x,y,a,b,c,d:int64;

    procedure shu(o,p,q:int64;var u,v:int64);

    var e,f,g,h:int64;

    begin

    e:=p div o;f:=q div o;

    p:=p mod o;q:=q mod o;

    if (p=0)and(q=0) then begin u:=e;v:=f;end

    else begin

    if p=1 then begin g:=o;h:=-q;if h

  • 0
    @ 2009-09-27 09:53:17

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-09-12 15:11:46

    楼下有一个这么做的,能不能讲一下道理?是模拟么?谢谢了!

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var

    n,i,j:longint;

    a,b:array[1..10]of longint;

    c,d:qword;

    begin

    readln(n);

    read(a[1],b[1]);c:=b[1];d:=a[1];

    for i:=2 to n do

    begin

    read(a[i],b[i]);

    while c mod a[i]b[i] do inc(c,d);

    d:=d*a[i];

    end;

    writeln(c);

    end.

  • 0
    @ 2009-09-10 18:44:08

    #include

    using namespace std;

    int main()

    {

    int n;

    cin>>n;

    long int sum=100000,i,j;

    int r[n],q[n];

    for (i=0;i>r[i]>>q[i];

    }

    for (i=1;i

信息

ID
1164
难度
6
分类
数论 | 解线性同余方程 点击显示
标签
递交数
4617
已通过
1159
通过率
25%
被复制
12
上传者