CCCherry

导航

凉肝的比赛

A - Mezo Playing Zoma

Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x=0x=0. Mezo starts sending nn commands to Zoma. There are two possible commands:

  • 'L' (Left) sets the position x:=x1x:=x−1;
  • 'R' (Right) sets the position x:=x+1x:=x+1.

Unfortunately, Mezo's controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position xx doesn't change and Mezo simply proceeds to the next command.

For example, if Mezo sends commands "LRLR", then here are some possible outcomes (underlined commands are sent successfully):

  • "LRLR" — Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position 00;
  • "LRLR" — Zoma recieves no commands, doesn't move at all and ends up at position 00 as well;
  • "LRLR" — Zoma moves to the left, then to the left again and ends up in position 2−2.

Mezo doesn't know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.

Input

The first line contains nn (1n105)(1≤n≤105) — the number of commands Mezo sends.

The second line contains a string ss of nn commands, each either 'L' (Left) or 'R' (Right).

Output

Print one integer — the number of different positions Zoma may end up at.

Example

Input
4
LRLR
Output
5

Note

In the example, Zoma may end up anywhere between 2−2 and 22.

思路:

就是求能达到的最左位置和最右位置所组成区间的长度

 

 

 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int t,l=0,r=0,p=0;C
 6     char s[100005];
 7     cin>>t;
 8     for(int i=0;i<t;i++)
 9     {
10         cin>>s[i];
11         if(s[i]=='L')
12             l++;
13         else r++;
14     }
15     p=l+r+1;
16     cout<<p;
17 }

C - Fadi and LCM

Today, Osama gave Fadi an integer XX , and Fadi was wondering about the minimum possible value of max(a,b)max(a,b) such that LCM(a,b)LCM(a,b) equals XX . Both aa and bb should be positive integers.

LCM(a,b)LCM(a,b) is the smallest positive integer that is divisible by both aa and bb . For example, LCM(6,8)=24LCM(6,8)=24 , LCM(4,12)=12LCM(4,12)=12 , LCM(2,3)=6LCM(2,3)=6 .

Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?

Input

The first and only line contains an integer XX (1X10121≤X≤1012 ).

Output

Print two positive integers, aa and bb , such that the value of max(a,b)max(a,b) is minimum possible and LCM(a,b)LCM(a,b) equals XX . If there are several possible such pairs, you can print any.

Examples

Input
2
Output
1 2
Input
6
Output
2 3
Input
4
Output
1 4
Input
1
Output
1 1

思路:降序枚举x的约数i,并判断i和j的最小公倍数是否是x,条件成立,输出;

 1 #include<iostream>
 2 #include <cmath>
 3 using namespace std;
 4 typedef long long ll;
 5 ll f(ll a,ll b)
 6 {
 7     if(b==0) return a;
 8     else return f(b,a%b);
 9 }
10 int main()
11 {
12     ll x;
13     cin>>x;
14     ll k=sqrt(x);
15     for(ll i=k;i>=1;i--)
16     {
17         if(x%i==0)
18         {
19             ll j=x/i;
20             ll g=f(i,j);
21             if(i*j/g==x)
22             {
23                 cout<<i<<" "<<j<<endl;
24                 return 0;
25             }
26             
27         }
28     }
29     return 0;
30 }

E - Deadline

Adilbek was assigned to a special project. For Adilbek it means that he has nn days to run a special program and provide its results. But there is a problem: the program needs to run for dd days to calculate the results.

Fortunately, Adilbek can optimize the program. If he spends xx (xx is a non-negative integer) days optimizing the program, he will make the program run in dx+1⌈dx+1⌉ days (a⌈a⌉ is the ceiling function: 2.4=3⌈2.4⌉=3 , 2=2⌈2⌉=2 ). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x+dx+1x+⌈dx+1⌉ .

Will Adilbek be able to provide the generated results in no more than nn days?

Input

The first line contains a single integer TT (1T501≤T≤50 ) — the number of test cases.

The next TT lines contain test cases – one per line. Each line contains two integers nn and dd (1n1091≤n≤109 , 1d1091≤d≤109 ) — the number of days before the deadline and the number of days the program runs.

Output

Print TT answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in nn days or NO (case insensitive) otherwise.

Example

Input
3
1 1
4 5
5 11
Output
YES
YES
NO

Note

In the first test case, Adilbek decides not to optimize the program at all, since dnd≤n .

In the second test case, Adilbek can spend 11 day optimizing the program and it will run 52=3⌈52⌉=3 days. In total, he will spend 44 days and will fit in the limit.

In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 22 days, it'll still work 112+1=4⌈112+1⌉=4 days.

思路:(参考董海铮dalao的题解

优化后所需时间是x+⌈d/(x+1)⌉,可化为x+1+d/(x+1)-1,由均值不等式可知,要使时间最少,x+1=d/(x+1),此时x=√d−1,此时时间为【2√d-1】;

 

 

 1 #include<iostream>
 2 #include <cmath>
 3 using namespace std;
 4 int main()
 5 {
 6     int t,n,d;
 7     cin>>t;
 8     while(t--)
 9     {
10         cin>>n>>d;
11         int t=ceil(2*sqrt(d)-1);
12         if(t<=n) 
13               cout<<"YES"<<endl;
14         else 
15               cout<<"NO"<<endl;
16     }
17 }                    

 

F - Yet Another Meme Problem

Try guessing the statement from this picture http://tiny.cc/ogyoiz.

You are given two integers AA and BB , calculate the number of pairs (a,b)(a,b) such that 1aA1≤a≤A , 1bB1≤b≤B , and the equation ab+a+b=conc(a,b)a⋅b+a+b=conc(a,b) is true; conc(a,b)conc(a,b) is the concatenation of aa and bb (for example, conc(12,23)=1223conc(12,23)=1223 , conc(100,11)=10011conc(100,11)=10011 ). aa and bb should not contain leading zeroes.

Input

The first line contains tt (1t1001≤t≤100 ) — the number of test cases.

Each test case contains two integers AA and BB (1A,B109)(1≤A,B≤109) .

Output

Print one integer — the number of pairs (a,b)(a,b) such that 1aA1≤a≤A , 1bB1≤b≤B , and the equation ab+a+b=conc(a,b)a⋅b+a+b=conc(a,b) is true.

Example

Input
3
1 11
4 2
191 31415926
Output
1
0
1337

Note

There is only one suitable pair in the first test case: a=1a=1 , b=9b=9 (1+9+19=191+9+1⋅9=19 ).

思路:

一开始用暴力果然超时了,没想到!ab+a+b=a10n+b,居然可以化简成b=10n1!!!因此b是任意个位数字为9的数,所以只要确定b的个数乘a的数就是答案;

 1 #include <iostream>
 2 #include <cmath>
 3 using namespace std;
 4 int main()
 5 {
 6     long long t,A,B;
 7     cin>>t;
 8     while(t--)
 9     {
10         cin>>A>>B;
11         long long k=0,w=0;
12         while(k<=B)
13         {
14             k=k*10+9;
15             w++;
16         }
17         w--;
18         cout<<A*w<<endl;
19     }
20 }

G - HQ9+

HQ9+ is a joke programming language which has only four one-character instructions:

  • "H" prints "Hello, World!",
  • "Q" prints the source code of the program itself,
  • "9" prints the lyrics of "99 Bottles of Beer" song,
  • "+" increments the value stored in the internal accumulator.

Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.

You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.

Input

The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.

Output

Output "YES", if executing the program will produce any output, and "NO" otherwise.

Examples

Input
Hi!
Output
YES
Input
Codeforces
Output
NO

Note

In the first case the program contains only one instruction — "H", which prints "Hello, World!".

In the second case none of the program characters are language instructions.

思路:

只要脑子别抽筋,知道‘+’是没有输出的就一定能AC啦!

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     char a,s[5]="HQ9";
 7     while((a=getchar())!='\n')
 8     {
 9         for(int i=0;i<3;i++)
10         {
11             if(a==s[i])
12             {
13                 cout<<"YES";
14                 return 0;
15             }
16             
17         }
18     }
19         cout<<"NO";
20 }

posted on 2020-01-17 16:28  CCCherry  阅读(219)  评论(0编辑  收藏  举报