记录编号 341005 评测结果 AAAAAAAAAA
题目名称 倒酒 最终得分 100
用户昵称 GravatarPhosphorus15 是否通过 通过
代码语言 C++ 运行时间 0.035 s
提交时间 2016-11-07 10:22:53 内存使用 0.25 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>

//using std::cin;
using std::cout;
using std::endl;

class input{
public:
  input & operator >>(long long & i){
    i = 0;
    char c = getchar();
    while(!(c>='0'&&c<='9')){
      c = getchar();
    }
    while(c>='0'&&c<='9'){
      i = i * 10 + (c-'0');
      c = getchar();
    }
  }
};

input cin;

long long ex_euclid(long long a,long long b,long long & x,long long & y){
  if(!a){
    x = 0;
    y = 1;
    return b;
  }else{
    long long d = ex_euclid(b%a,a,y,x);
    x -= b / a * y;
    return d;
  }
}

int main(int argc,char ** argv){
  freopen("pour.in","r",stdin);
  freopen("pour.out","w+",stdout);
  long long a,b,c,x,y;
  cin>>a>>b;
  c = ex_euclid(a,b,x,y);
  cout<<c<<endl;
  x = -x;
  if(x<0){
    y+=(-x+b/c-1)/(b/c)*(a/c);
    x+=(-x+b/c-1)/(b/c)*(b/c);
  }
  cout<<x<<" "<<y<<endl;
  return 0;
}