110 条题解

  • -1
    @ 2016-08-30 15:18:52

    #include"stdio.h"
    #include"iostream"
    #include"math.h"
    #include"algorithm"

    using namespace std;
    typedef long long ll;
    /*
    void gcd(int a,int b,int &d,int &x,int &y)
    {
    if(b==0){d=a;x=1;y=0;return;}
    int x1,y1;
    gcd(b,a%b,d,x1,y1);
    int t1,t2;
    t1=x1;t2=y1;
    x=t2;y=t1-(a/b)*t2;
    }
    */
    void gcd(ll a,ll b,ll &d,ll &x,ll &y)
    {
    if(!b){d=a;y=0;x=1;}
    else{
    gcd(b,a%b,d,y,x);y-=(a/b)*x;
    }
    }
    int main()
    {
    ll m,n,l,x,y;
    while(scanf("%I64d%I64d%I64d%I64d%I64d",&x,&y,&m,&n,&l)==5)
    {
    ll a,b,c;
    a=m-n;b=l;c=(y-x);
    if(a<0)
    {
    a=-a;c=-c;
    }
    ll sx,sy,g;
    gcd(a,b,g,sx,sy);
    if(c%g)
    {
    puts("Impossible");continue;
    }
    b/=g;
    c/=g; //倍数

    ll t=c*sx;
    printf("%d\n",(t+b)%b);

    }
    return 0;
    }

  • -1
    @ 2016-08-30 15:18:45

    测试数据 #0: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    Accepted, time = 0 ms, mem = 560 KiB, score = 100

  • -1
    @ 2016-04-02 19:39:01

    测试数据 #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 = 548 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 552 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    Accepted, time = 15 ms, mem = 552 KiB, score = 100

    http://www.cnblogs.com/Coolxxx/p/5348092.html

  • -1
    @ 2015-11-12 22:00:37

    原题目等价于求方程 ax=b(mod l)

    我的步骤如下:
    一、化简系数,三个系数a,b,l同时除以它们的最大公约数。
    二、用辗转相除法,计算出am+ln=gcd(a,l)中的m和n。
    三、由二中的m,有
    am = gcd(a,l) (mod l)
    => am*(b/gcd(a,l)) = gcd(a,l)*(b/gcd(a,l)) (mod l)
    => a*(mb/gcd(a,l)) = b (mod l)
    => x = (mb / gcd(a,l)) (mod l)

  • -1
    @ 2015-04-07 21:49:09

    #include <vector>
    #include <list>
    #include <limits.h>
    #include <map>
    #include <set>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <bitset>
    #include <algorithm>
    #include <functional>
    #include <numeric>
    #include <utility>
    #include <sstream>
    #include <iostream>
    #include <iomanip>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <string.h>
    #include <stdlib.h>
    using namespace std;

    long long L;

    long long extended_euclidean(long long a, long long b, long long &x, long long &y){
    if(b==0){
    x = 1;
    y = 0;
    return a;
    }
    long long g = extended_euclidean(b, a%b, x, y);
    long long tmp = x;
    x = y;
    y = tmp - (a/b)*y;
    return g;
    }

    int main(){

    long long x, y, m, n;
    cin>>x>>y>>m>>n>>L;
    long long a = (m-n+L)%L;
    long long b = L;
    long long c = (y-x+L)%L;
    long long g = extended_euclidean(a, b, x, y);
    if(c%g != 0){
    cout<<"Impossible"<<endl;
    return 0;
    }
    long long k = c/g;
    x = (x*k);
    if(x < 0)
    x = (L/g-(abs(x)%(L/g)));
    if((x-L/g) > 0)
    x = x%(L/g);
    cout<<x<<endl;
    return 0;
    }
    一句话:**扩欧**
    头文件是模板,程序是复制的,搬运了一下
    原网页

  • -1
    @ 2015-03-23 13:41:29

    #include<iostream>
    #include<math.h>
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;

    void gcd(int a,int b,int &d,int&x,int &y){
    if (b == 0){
    d = a;
    x = 1;
    y = 0;
    }else{
    gcd(b, a%b, d, y, x);
    y -= x*(a / b);
    }
    }

    int main(){
    freopen("in.txt", "r", stdin);
    int x1, x2, v1, v2,len;
    cin >> x1 >> x2 >> v1 >> v2 >> len;
    int dx, dv;
    v1 %= len;
    v2 %= len;
    x1 %= len;
    x2 %= len;
    if (v1 < v2){
    swap(v1, v2);
    swap(x1, x2);
    }
    dv = v1 - v2;
    if (x1<x2){
    dx = x2 - x1;
    }
    else{
    dx = x2+len-x1;
    }
    int d, k,p;
    gcd(dv,len, d,k,p);
    if (dx%d){
    cout << "Impossible" << endl;
    }
    else{
    dv /= d;
    len /= d;
    if (k > 0){

    cout << (dx*k / d)%len << endl;
    }
    else{

    cout << ((len + k)*dx / d)%len << endl;
    }
    }
    return 0;
    }

  • -1
    @ 2014-10-20 22:08:06

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

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

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

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

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

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

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

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

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

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

    Accepted, time = 0 ms, mem = 528 KiB, score = 100

  • -1
    @ 2014-08-23 22:04:04

    千万别信那两个用pascal写的,纯粹扯淡
    这是AC的
    ###Block code
    #include<cstdio>
    using namespace std;
    long long m,n,x,y,l,k,s,a,b,d;
    void swap(long long &x,long long &y){//{{{
    long long t;
    t=x,x=y,y=t;
    }//}}}
    void work(long long a,long long b,long long &x,long long &y){//{{{
    if(a==1){
    x=1,y=0;
    return;
    }
    long long x1,y1;
    work(b%a,a,x1,y1);
    y=x1,x=y1-x1*int(b/a);
    }//}}}
    long long gcd(long long a,long long b){///{{{
    if(a==0)return b;
    else return gcd(b%a,a);
    }//}}}
    int main()
    {
    scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l);
    if(n>m){
    swap(m,n);
    swap(x,y);
    }
    m-=n,y-=x,m%=l,y%=l;
    if(m==0){
    printf("Impossible");
    return 0;
    }
    while(y<0)y+=l;
    if(gcd(m,l)!=1){
    d=gcd(m,l);
    m/=d,l/=d;
    if(y%d!=0){
    printf("Impossible");
    return 0;
    }
    y/=d;
    }
    work(m,l,s,k);
    while(s<0)s+=l;
    s*=y,s%=l;
    printf("%lld",s);
    return 0;
    }

  • -1
    @ 2013-08-31 14:05:06
  • -1
    @ 2013-07-29 17:23:31
  • -1
    @ 2013-06-24 19:56:28

    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
    int x,y,m,n,l,i,t=0,tool=0;
    scanf("%d %d %d %d %d",&x,&y,&m,&n,&l);
    if(m<n)
    {
    i=0;
    while(tool==0)
    {
    if(x+m*i==y+n*i||i>1000)
    {
    tool=1;
    t=i;
    }
    else
    i++;
    }
    }
    else
    {
    i=0;
    while(tool==0||i>1000)
    {
    if(x+m>l)
    x=x+m-l;
    else
    x=x+m;
    if(y+n>l)
    y=x+n-l;
    else
    y=y+n;
    if(x==y)
    {
    tool=1;
    t=i;
    }
    else
    i++;
    }
    }
    if(t!=0)
    printf("%d",t);
    else
    printf("imposible");
    return 0;
    }

  • -1
    @ 2013-03-23 10:25:55

    那位大神帮忙看看我这程序那里错了。。。
    #include <iostream>
    #include <string>
    #include <math.h>
    #include <time.h>
    #include <stdio.h>
    using namespace std;
    int main()
    {
    long long x, y, m, n, l;
    float days = 0;
    float distance = 0;
    int i;
    cin>>x>>y>>m>>n>>l;
    if (x > y) {
    distance = x - y;
    }
    if (x < y) {
    distance = y - x;
    }
    if (x == y)
    {
    cout<< 0;
    return 0;
    }
    if (m == n)
    {
    cout<<"Impossible";
    return 0;
    }

    if (m > n)
    {
    days = distance / (m - n);
    }
    if (m < n)
    {
    days = (l - distance) / (n - m);
    }
    i=days;
    if (days > i)
    {
    cout<<i+1;
    }
    if (days == i)
    {
    cout<<i;
    }
    cout<<endl;
    return 0;
    }

  • -1
    @ 2010-07-03 09:09:38

    var

    x,y,m,n:1..2000000000;

    l:1..2100000000;

    begin

    read(x,y,m,n,l);

    if m=n then write('Imppossible')

    else if m>n then write(abs(x-y)div(m-n))

    else write((l-abs(x-y))div(n-m));

    end.

  • -1
    @ 2010-04-04 11:48:10

    var

    x,y,m,n:1..2000000000;

    l:1..2100000000;

    begin

    read(x,y,m,n,l);

    if m=n then write('Imppossible')

    else if m>n then write(abs(x-y)div(m-n))

    else write((l-abs(x-y))div(n-m));

    end.

  • -1
    @ 2010-03-27 18:54:19

    本人看不懂,于是自己编了一个自己推算的程序

    a*k=b( mod c)

    ---|-->a*k=b+c*l---|-->c*l=-b+a*k---|->c*l=-b ( mod a)

    把原方程转化为规模较小的方程,递归求解。。。。

    边界条件:b mod a=0 时k= b div a;a=0时无解

  • -1
    @ 2009-11-10 20:20:56

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • -1
    @ 2009-11-09 14:13:32

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • -1
    @ 2009-11-04 12:13:19

    int64真不是一般的变态.除了读入和赋值的BUG外,还有就是 mod 负数也会出错.比如 int64 类型下,-1 mod -5 = 1.

    • @ 2013-11-09 17:32:30

      pascal mod 都这样

    • @ 2018-11-08 08:26:51

      @wajiyu 那是你自己不会用,不要在这里误导新人

  • -1
    @ 2009-11-09 08:50:45

    庆祝100题。。。。。。

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

信息

ID
1009
难度
8
分类
数论 点击显示
标签
递交数
7019
已通过
1067
通过率
15%
被复制
33
上传者