比赛 防止浮躁的小练习v0.9 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 殉国 最终得分 100
用户昵称 Phosphorus15 运行时间 0.061 s
代码语言 C++ 内存使用 0.30 MiB
提交时间 2016-11-07 09:09:55
显示代码纯文本
#include <iostream>
#include <cstdio>

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

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

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