10.11

目录

A-Consecutive Sum Riddle

 题意:

思路:

代码:

B-Special Numbers

题意:

思路:

代码:

C-Make Them Equal

题意:

思路:

代码:


A-Consecutive Sum Riddle

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 -10^{18} \le l < r \le 10^{18}−1018≤l<r≤1018 and l + (l + 1) + \ldots + (r - 1) + r = nl+(l+1)+…+(r−1)+r=n.

Input

The first line contains a single integer tt (1 \le t \le 10^41≤t≤104) — the number of test cases.

The first and only line of each test case contains a single integer nn (1 \le n \le 10^{18}1≤n≤1018).

Output

For each test case, print the two integers ll and rr such that -10^{18} \le l < r \le 10^{18}−1018≤l<r≤1018 and l + (l + 1) + \ldots + (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

7
1
2
3
6
100
25
3000000000000

Output

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.

 题意:

输入一个整数n让你找到一个区间[l,r]使得区间内所有整数相加等于n.

思路:

l=1-n,r=n.

代码:

#include<iostream>
#include<algorithm>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cstdlib>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        cout<<1-n<<" "<<n<<endl;
    }
}

B-Special Numbers

Theofanis really likes sequences of positive integers, thus his teacher (Yeltsa Kcir) gave him a problem about a sequence that consists of only special numbers.

Let's call a positive number special if it can be written as a sum of different non-negative powers of nn. For example, for n = 4n=4 number 1717 is special, because it can be written as 4^0 + 4^2 = 1 + 16 = 1740+42=1+16=17, but 99 is not.

Theofanis asks you to help him find the kk-th special number if they are sorted in increasing order. Since this number may be too large, output it modulo 10^9+7109+7.

Input

The first line contains a single integer tt (1 \le t \le 10^41≤t≤104) — the number of test cases.

The first and only line of each test case contains two integers nn and kk (2 \le n \le 10^92≤n≤109; 1 \le k \le 10^91≤k≤109).

Output

For each test case, print one integer — the kk-th special number in increasing order modulo 10^9+7109+7.

Example

Input

3
3 4
2 12
105 564

Output

9
12
3595374

Note

For n = 3n=3 the sequence is [1,3,4,9...][1,3,4,9...]

题意:

输入n,k。定义特殊的数:可以由n的任意不同次方相加而成的数。输出按升序排序的第k个特殊的数。

思路:

将k的二进制每一位看成n进制转换成10进制即可。

代码:
 

#include<iostream>
#include<algorithm>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cstdlib>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        ll q=1;
        ll ans=0;
        while(k)
        {
            if(k&1)
            {
                ans+=q;
                ans%=mod;
            }
            q*=n;
            q%=mod;
            k>>=1;

        }
        cout<<ans%mod<<endl;
    }
}

C-Make Them Equal

Theofanis has a string s_1 s_2 \dots s_ns1​s2​…sn​ and a character cc. He wants to make all characters of the string equal to cc using the minimum number of operations.

In one operation he can choose a number xx (1 \le x \le n1≤x≤n) and for every position ii, where ii is not divisible by xx, replace s_isi​ with cc.

Find the minimum number of operations required to make all the characters equal to cc and the xx-s that he should use in his operations.

Input

The first line contains a single integer tt (1 \le t \le 10^41≤t≤104) — the number of test cases.

The first line of each test case contains the integer nn (3 \le n \le 3 \cdot 10^53≤n≤3⋅105) and a lowercase Latin letter cc — the length of the string ss and the character the resulting string should consist of.

The second line of each test case contains a string ss of lowercase Latin letters — the initial string.

It is guaranteed that the sum of nn over all test cases does not exceed 3 \cdot 10^53⋅105.

Output

For each test case, firstly print one integer mm — the minimum number of operations required to make all the characters equal to cc.

Next, print mm integers x_1, x_2, \dots, x_mx1​,x2​,…,xm​ (1 \le x_j \le n1≤xj​≤n) — the xx-s that should be used in the order they are given.

It can be proved that under given constraints, an answer always exists. If there are multiple answers, print any.

Example

Input

3
4 a
aaaa
4 a
baaa
4 b
bzyx

Output

0
1
2
2 
2 3

Note

Let's describe what happens in the third test case:

  1. x_1 = 2x1​=2: we choose all positions that are not divisible by 22 and replace them, i. e. bzyx \rightarrow→ bzbx;
  2. x_2 = 3x2​=3: we choose all positions that are not divisible by 33 and replace them, i. e. bzbx \rightarrow→ bbbb.

题意:

输入一个长度为n的字符串和一个字符c,每次操作可以选择一个x∈[1,n]对位置i∈[1,n]将满足i不能被x整除的位置的字符变成c,问最少多少次操作使字符串全由字符c组成,并输出每个x。

思路:

0次:字符串本来就全由字符c组成。

1次:遍历每个可能的x,只要x的倍数对应的位置上字符全为字符c即可。

2次:如果没有找到执行1次就可以满足的操作,那么最多只要两次,x分别为n,n-1。

代码:

#include<iostream>
#include<algorithm>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cstdlib>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        string a;
        char c;
        ll n;
        cin>>n>>c;
        cin>>a;
        int flag=1;
        for(ll i=0;i<n;i++)
        {
            if(a[i]!=c)
            {
                flag=0;
                break;
            }
        }
        if(flag==1)
        {
            cout<<0<<endl;
            continue;
        }
        int flag1=0;
        int ans;
        for(int i=2;i<=n;i++)
        {
            int flag2=1;
            for(int j=i;j<=n;j+=i)
            {
                if(a[j-1]!=c)
                {
                    flag2=0;
                    break;
                }
            }
            if(flag2==1)
            {
                flag1=1;
                ans=i;
                break;
            }
        }
        if(flag1==1)
            cout<<1<<endl<<ans<<endl;
        else
            cout<<2<<endl<<n-1<<" "<<n<<endl;

    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值