A. Consecutive Sum Riddle( Codeforces Round #747 (Div. 2))

本文探讨了一道趣味数学题目,寻找两个整数l和r,使得它们之间的连续整数之和等于给定整数n。通过巧妙的方法,文章提供了一个简单而有效的解决方案,并附带示例进行说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题:

Theofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese).

You are given an integer nn. You need to find two integers ll and rr such that −1018≤l<r≤1018−1018≤l<r≤1018 and l+(l+1)+…+(r−1)+r=nl+(l+1)+…+(r−1)+r=n.

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The first and only line of each test case contains a single integer nn (1≤n≤10181≤n≤1018).

Output

For each test case, print the two integers ll and rr such that −1018≤l<r≤1018−1018≤l<r≤1018 and l+(l+1)+…+(r−1)+r=nl+(l+1)+…+(r−1)+r=n.

It can be proven that an answer always exists. If there are multiple answers, print any.

Example

input

Copy

7
1
2
3
6
100
25
3000000000000

output

Copy

0 1
-1 2 
1 2 
1 3 
18 22
-2 7
999999999999 1000000000001

Note

In the first test case, 0+1=10+1=1.

In the second test case, (−1)+0+1+2=2(−1)+0+1+2=2.

In the fourth test case, 1+2+3=61+2+3=6.

In the fifth test case, 18+19+20+21+22=10018+19+20+21+22=100.

In the sixth test case, (−2)+(−1)+0+1+2+3+4+5+6+7=25(−2)+(−1)+0+1+2+3+4+5+6+7=25.

卡点:

1.最小的负数边界点怎么确定

2.想用二分

标签:

1.找规律、数学

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll l,r,n;
int t;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&n);
        printf("%lld %lld\n",-n+1,n);
    }
    return 0;
}

总结:其实很简单,不要被样例给误导了,答案有多个只需要输出一个。

因为是加法,连续加,递增数列,那么其实每个数都可以出现在加的数里,只需要把前面多的一连串用相应的复数形式抵消掉就好了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~晚风微凉~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值