QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#581119#9381. 502 Bad GatewayhezlikCompile Error//C++141.4kb2024-09-22 09:39:452024-09-22 09:39:45

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-22 09:39:45]
  • 评测
  • [2024-09-22 09:39:45]
  • 提交

answer

#include <bits/stdc++.h>

typedef long long int64;

struct frac{
  
  int64 x,y;
  
  frac():x(0),y(1){}
  frac(int64 n):x(n),y(1){}

  frac(int64 _x,int64 _y){
    if (!_y)
      assert(0);
    if (!_x){
      x=0;y=1;
    }else{
      bool neg=0;
      if ((_x<0)!=(_y<0)) neg=1;
      if (_x<0) _x=-_x;
      if (_y<0) _y=-_y;
      int64 _g=std::gcd(_x,_y);
      x=_x/_g;
      y=_y/_g;
      if (neg) x=-x;
    }
  }

  friend frac operator+(const frac &a,const frac &b){
    return frac(a.x*b.y+b.x*a.y,a.y*b.y);
  }

  friend frac operator-(const frac &a,const frac &b){
    return frac(a.x*b.y-b.x*a.y,a.y*b.y);
  }

  friend frac operator*(const frac &a,const frac &b){
    return frac(a.x*b.x,a.y*b.y);
  }
  
  friend frac operator/(const frac &a,const frac &b){
    return frac(a.x*b.y,a.y*b.x);
  }

  friend bool operator<(const frac &a,const frac &b){
    return (__int128)a.x*b.y<(__int128)a.y*b.x;
  }

  friend bool operator>(const frac &a,const frac &b){
    return (__int128)a.x*b.y>(__int128)a.y*b.x;
  }

};

void work(){
  int64 t;
  std::cin>>t;
  auto calc=[&](int64 c){
    return frac(c-1,2)+frac(t,c);
  };
  int64 c=(int64)sqrt(2*t);
  frac ans=calc(c);
  if (c<t) ans=std::min(ans,calc(c+1));
  std::cout<<ans.x<<' '<<ans.y<<'\n';
}

int main(){
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int T=1;
  std::cin>>T;
  for (;T--;) work();
  return 0;
}

詳細信息

answer.code: In constructor ‘frac::frac(int64, int64)’:
answer.code:22:21: error: ‘gcd’ is not a member of ‘std’
   22 |       int64 _g=std::gcd(_x,_y);
      |                     ^~~