cf 21.10.8 div2 #747

Problem - A - Codeforces

题目大意:

共有T组测试数据,每组数据给定一个n。

给定一个 n, 找到一个 -10^1^8 \leq l < r \leq 10^1^8 使得 l + ( l + 1 ) + ... + ( r - 1 ) + r = n。

其中 1 \leq n \leq 10^1^8

Example

Input

7
1
2
3
6
100
25
3000000000000


Output

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

思路:

观察 n == 2 时的输出

可发现 令 l = -  ( n + 1 ), r = n 即可。

AC代码:
 

#include <iostream>

using namespace std;

int main()
{
	int T;
	cin >> T;
	long long n;
	
	while(T--)
	{
		cin >> n;
	
		cout << -(n - 1) << " " << n << endl;
	}
	
	return 0;
}

Problem - B - Codeforcest

 题目大意:

共T组数据,每组数据给定一个 n, k。

其中,每个 n 决定一个数列,为 n 的各次幂的和组成的升序序列。

如 n = 3 时 这个数列为 {1,3,4,9...},输出这个数列的第 k 个数。

思路:

利用二进制特性,将 k 转化为二进制,从第0位开始以此检验 k 第 i 位是否为1,若第 i 位为1,则res += 3^i 所得 res 即为答案。

Example

Input

3
3 4
2 12
105 564

Output

9
12
3595374

AC代码:

#include <iostream>

using namespace std;

const int mod = 1e9 + 7;

int main()
{
	int t;
	cin >> t;
	
	while(t--)
	{
		int n, k;
		cin >> n >> k;
		
		long long m = 1;
		long long res = 0;
		
		for(int i = 0; i < 30; i++)
		{
			if((k >> i) & 1)
				res += m;
			m *= n;
			m %= mod;
		}
		res %= mod;
		cout << res << endl;
	}
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值