Educational Codeforces Round 57 (Rated for Div. 2)

本文解析了三道算法竞赛题目,包括寻找整除数对、子字符串移除后的字符相等计数,以及寻找满足特定角度的正多边形。通过详细分析与代码实现,为读者提供了深入理解算法思路的机会。

A. Find Divisible

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a range of positive integers from ll to rr.

Find such a pair of integers (x,y)(x,y) that l≤x,y≤rl≤x,y≤r, x≠yx≠y and xx divides yy.

If there are multiple answers, print any of them.

You are also asked to answer TT independent queries.

Input

The first line contains a single integer TT (1≤T≤10001≤T≤1000) — the number of queries.

Each of the next TT lines contains two integers ll and rr (1≤l≤r≤9982443531≤l≤r≤998244353) — inclusive borders of the range.

It is guaranteed that testset only includes queries, which have at least one suitable pair.

Output

Print TT lines, each line should contain the answer — two integers xx and yy such that l≤x,y≤rl≤x,y≤r, x≠yx≠y and xx divides yy. The answer in the ii-th line should correspond to the ii-th query from the input.

If there are multiple answers, print any of them.

Example

input

3
1 10
3 14
1 10

output

1 7
3 9
5 10
#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;
	scanf("%d",&T);
	long long a,b,c,d;
	while(T--){
		scanf("%lld%lld",&a,&b);
		c=a;
		for(int i=2;;i++){
			if(i*c<=b){
				d=i*c;
				break;
			}
			else {
				d=c;
				break;
			}
		}
		printf("%lld %lld\n",c,d);
	}
}

B. Substring Removal

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a string ss of length nn consisting only of lowercase Latin letters.

A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.

Your task is to calculate the number of ways to remove exactly one substring from this string in such a way that all remaining characters are equal (the number of distinct characters either zero or one).

It is guaranteed that there is at least two different characters in ss.

Note that you can remove the whole string and it is correct. Also note that you should remove at least one character.

Since the answer can be rather large (not very large though) print it modulo 998244353998244353.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

Input

The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of the string ss.

The second line of the input contains the string ss of length nn consisting only of lowercase Latin letters.

It is guaranteed that there is at least two different characters in ss.

Output

Print one integer — the number of ways modulo 998244353998244353 to remove exactly one substring from ss in such way that all remaining characters are equal.

Examples

input

4
abaa

output

6

input

7
aacdeee

output

6

input

2
az

output

3

Note

Let s[l;r]s[l;r] be the substring of ss from the position ll to the position rr inclusive.

Then in the first example you can remove the following substrings:

  • s[1;2]s[1;2];
  • s[1;3]s[1;3];
  • s[1;4]s[1;4];
  • s[2;2]s[2;2];
  • s[2;3]s[2;3];
  • s[2;4]s[2;4].

In the second example you can remove the following substrings:

  • s[1;4]s[1;4];
  • s[1;5]s[1;5];
  • s[1;6]s[1;6];
  • s[1;7]s[1;7];
  • s[2;7]s[2;7];
  • s[3;7]s[3;7].

In the third example you can remove the following substrings:

  • s[1;1]s[1;1];
  • s[1;2]s[1;2];
  • s[2;2]s[2;2].
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int N=2e5+5;
char s[N];
int main(){
	int n;
	scanf("%d%s",&n,s+1);
	long long l,r,ans;
	for(l=1;l<=n;l++)
	if(s[l+1]!=s[l])
	break;
	for(r=n;r>=1;r--)
	if(s[r]!=s[r-1])
	break;
	if(s[1]!=s[n])
	ans=(l+n-r+1)%mod;
	else ans=((l+n-r+1)+(l*(n-r+1)))%mod; 
	printf("%lld\n",ans+1);
}

C. Polygon for the Angle

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an angle angang.

The Jury asks You to find such regular nn-gon (regular polygon with nn vertices) that it has three vertices aa, bb and cc (they can be non-consecutive) with ∠abc=ang∠abc=ang or report that there is no such nn-gon.

If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353998244353.

Input

The first line contains single integer TT (1≤T≤1801≤T≤180) — the number of queries.

Each of the next TT lines contains one integer angang (1≤ang<1801≤ang<180) — the angle measured in degrees.

Output

For each query print single integer nn (3≤n≤9982443533≤n≤998244353) — minimal possible number of vertices in the regular nn-gon or −1−1 if there is no such nn.

Example

input

4
54
50
2
178

output

10
18
90
180

Note

The answer for the first query is on the picture above.

The answer for the second query is reached on a regular 1818-gon. For example, ∠v2v1v6=50∘∠v2v1v6=50∘.

The example angle for the third query is ∠v11v10v12=2∘∠v11v10v12=2∘.

In the fourth query, minimal possible nn is 180180 (not 9090).

#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		int ans=__gcd(n,180);
		ans=180/ans;
		while(180*(ans-2)/ans<n)
		ans*=2;
		printf("%d\n",ans);
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值