题解 | 小红的区间构造

小红的区间构造

https://www.nowcoder.com/practice/df1bbce22cad4d2a8b69b7db3715e651

//  #牛客春招刷题训练营# https://www.nowcoder.com/discuss/726480854079250432
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  long long n, k, x;//--------乘后会溢出,记得记得开ll
  cin >> n >> k >> x;
  if (k > (x) * (n + 1) - 1 || k < x * (n - 1) + 1) puts("-1");//------先判断极限情况
  else{
    int rest = k - (x * (n - 1) + 1);
    if (rest > x - 1){//---------优先补充最后一个倍数点后面的非倍数数,只需计算区间左界即可,右界加出
      cout << x - (rest - (x - 1)) << " " << x - (rest - (x - 1)) + k - 1;
    }
    else{
      cout << x << " " << x + k - 1;
    }
  }
}
// 64 位输出请用 printf("%lld")

#牛客春招刷题训练营##写题解领奖励#
全部评论
评论
点赞
收藏
分享

全站热榜

更多

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务