Consecutive Sum Riddle(800)

在这里插入图片描述
题意 :

  • 给一n,求l和r,满足l加到r之和为n

思路 :

  • 1 e 18 1e18 1e18,所以即使用等差数列公式优化枚举r的一重循环也是不可能的
  • 想到 [ − ( n − 1 ) , n ] [-(n-1),n] [(n1),n]肯定是可以的
#include <iostream>
#define endl '\n'
 
using namespace std;
 
typedef long long ll;
 
void solve()
{
    
    
    ll n;
    cin >> n;
    cout << -(n - 1) << ' ' << n << endl;
}
 
int main()
{
    
    
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int _ = 1;
    cin >> _;
    
    while (_ -- )
    {
    
    
        solve();
    }
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_51448653/article/details/121447502