You are given a range of positive integers from l to r .
Find such a pair of integers (x,y) that l≤x,y≤r , x≠y and x divides y .
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1≤T≤1000 ) — the number of queries.
Each of the next T lines contains two integers l and r (1≤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 T lines, each line should contain the answer — two integers x and y such that l≤x,y≤r , x≠y and x divides y . The answer in the i -th line should correspond to the i -th query from the input.
If there are multiple answers, print any of them.
代码:
#include
#include
#include
#include
#include
#include
#define inf 0x3fffffff
using namespace std;
int main()
{
int t,x,y,m;
cin>>t;
while(t--)
{
cin>>x>>y;
m=y/x;
if(m>1)
cout<
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 s.
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 998244353.
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 n (2≤n≤2⋅105) — the length of the string s.
The second line of the input contains the string s of length n 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 998244353 to remove exactly one substring from ss in such way that all remaining characters are equal.
分析:字符串去掉子串(连续的)后各字符需要满足的要求
1.剩余字符数量可以为0。
2.剩余字符中不同种字符相互间数量相等。
3.剩余字符中存在不同的字符种类为0或1种。(比赛的时候把这条看漏的我哭唧唧)
因为去掉的子串是连续的,所以直接判断首尾的字符种类和数量就好了。
代码:
#include
#include
#include
#include
#include
#include
#define mod 998244353
using namespace std;
int main()
{
int n;
long long a=1,b=1;
string s;
cin>>n>>s;
while(a)
{
if(s[a]!=s[0]) break;
a++;
}
while(b)
{
if(s[n-b-1]!=s[n-1]) break;
b++;
}
// cout<
You are given an angle angang.
The Jury asks You to find such regular n-gon (regular polygon with nn vertices) that it has three vertices a, b and c (they can be non-consecutive) with ∠abc=ang or report that there is no such n-gon.
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.
Input
The first line contains single integer T (1≤T≤180) — the number of queries.
Each of the next T lines contains one integer ang (1≤ang<180) — the angle measured in degrees.
Output
For each query print single integer nn (3≤n≤998244353) — minimal possible number of vertices in the regular n-gon or −1 if there is no such n.
分析:假设取n边形一点为顶点,另取两个相邻顶点组成n边形的单位角p=180/n。
当ang能被p整除的话,n满足题意。设正整数m使ang=m*p -> 180/ang=n/m。
所以将180/ang约为最简分数,分子为满足题意的最小n,分母为ang角夹的边长数。
判断m<=n-2 输出分子,反之输出分子的两倍。
代码:
#include
#include
#include
#include
#include
#include
#define inf 0x3fffffff
using namespace std;
int main()
{
int dg(int a,int b);
int t,x,n,m;
cin>>t;
while(t--)
{
cin>>x;
if(x>=180) cout<<-1<
Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length n consisting of lowercase Latin latters. Vasya thinks that the statement can be considered hard if it contains a subsequence hard; otherwise the statement is easy. For example, hard, hzazrzd, haaaaard can be considered hard statements, while har, hart and drah are easy statements.
Vasya doesn't want the statement to be hard. He may remove some characters from the statement in order to make it easy. But, of course, some parts of the statement can be crucial to understanding. Initially the ambiguity of the statement is 0, and removing i-th character increases the ambiguity by ai (the index of each character is considered as it was in the original statement, so, for example, if you delete character r from hard, and then character d, the index of d is still 4 even though you delete it from the string had).
Vasya wants to calculate the minimum ambiguity of the statement, if he removes some characters (possibly zero) so that the statement is easy. Help him to do it!
Recall that subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
Input
The first line contains one integer n (1≤n≤105) — the length of the statement.
The second line contains one string s of length n, consisting of lowercase Latin letters — the statement written by Vasya.
The third line contains n integers a1,a2,…,an(1≤ai≤998244353).
Output
Print minimum possible ambiguity of the statement after Vasya deletes some (possibly zero) characters so the resulting statement is easy.
分析:
if h-0 a-1 r-2 d-3 字符串为s
e(j) : 表示字符串中当前位置是 j 且是最后一个 j 的话一定满足题意的最小偏差。
if(s[i]=='h') e[0]+=a[i];
//因为h是hard的首位,所以前面的h都要去掉
if(s[i]=='a') e[1]=min(e[0],e[1]+a[i]);
//判断是去掉前面所有h还是i-1时候的e[1]加上去掉当前位置的a偏差更小
if(s[i]=='r') e[2]=min(e[1],e[2]+a[i]);
//同理,因为i-1时e[1]和e[0]比较过留下的e[1],所以直接和e[1]比较
if(s[i]=='d') e[3]=min(e[2],e[3]+a[i]);
//同上
//因为d是hard的末尾,直接输出e[3]
cout<
代码:
#include
#include
#include
using namespace std;
const int maxn=1e5+5;
int main()
{
int n,a[maxn],i;
long long b=0,c=0,d=0,e=0;
string s;
cin>>n>>s;
for(i=0;i>a[i];
i=-1;
while(s[++i])
{
if(s[i]=='h') b+=a[i];
else if(s[i]=='a') c=min(b,c+a[i]);
else if(s[i]=='r') d=min(c,d+a[i]);
else if(s[i]=='d') e=min(d,e+a[i]);
else;
}
cout<