比赛时候切了A-E,fst了A

Standings第一页只有三个人挂了A题,而我就是其中之一,真™开心啊蛤蛤蛤

 

A. Fake NP

time limit per test  1 second
memory limit per test  256 megabytes
input standard input
output standard output

Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.

You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.

Solve the problem to show that it's not a NP problem.

Input

The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).

Output

Print single integer, the integer that appears maximum number of times in the divisors.

If there are multiple answers, print any of them.

Examples
input
19 29
output
2
input
3 6
output
3
Note

Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html

The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.

The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.

 

脑洞题

求被[l,r]范围的数拥有的最多的因数。

如果l==r就输出l,如果l<r就输出2,正确性显然

只要5行就可以AC呢

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main(){
 5     int l,r;
 6     scanf("%d%d",&l,&r);
 7     if(l==r)printf("%d\n",l);
 8     else printf("2\n");
 9     return 0;
10 }

 

看到题的时候蠢兮兮枚举sqrt范围内的数,算1~r的贡献减去1~l-1的贡献。

其实这样也可以龟速跑过的吧?但是减的时候减了1~l的贡献,PP以后还自信锁题试图hack别人,这就回天无力了。(PP都是骗人的)

 

B. 3-palindrome
time limit per test  1 second
memory limit per test  256 megabytes
input standard input
output standard output

In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.

He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.

Input

The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.

Output

Print the string that satisfies all the constraints.

If there are multiple answers, print any of them.

Examples
input
2
output
aa
input
3
output
bba
Note

palindrome is a sequence of characters which reads the same backward and forward.

 

看上去是个贪心递推?假的!

abbaabbaabba无限循环即可

或者"aabb"也可以

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<cmath>
 6 using namespace std;
 7 const int mxn=200010;
 8 int read(){
 9     int x=0,f=1;char ch=getchar();
10     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
11     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
12     return x*f;
13 }
14 char s[mxn];
15 int n;
16 bool check(int i,char c){
17     if(s[i-1]==c)return 0;
18     return 1; 
19 }
20 int main(){
21     int i,j;
22     n=read();
23     for(i=1;i<=n;i++){
24         if(i%4==1)printf("a");
25         else if(i%4==2)printf("b");
26         else if(i%4==3)printf("b");
27         else if(i%4==0)printf("a");
28     }
29     printf("\n");
30     return 0;
31 }
B

 

C. Find Amir

time limit per test  1 second
memory limit per test  256 megabytes
input standard input
output standard output

A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.

There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j costs Codeforces Round #411 (Div. 2) A-F and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of schools.

Output

Print single integer: the minimum cost of tickets needed to visit all schools.

Examples
input
2
output
0
input
10
output
4
Note

In the first example we can buy a ticket between the schools that costs Codeforces Round #411 (Div. 2) A-F.

 

贪心 构造

构造题真开心

代价是$ \mod (n+1) $意义下计算的,脑洞一下可以发现1 to n , 2 to n-1 3 to n-2 这样的走法代价为0,而n to 2,n-1 to 3这样的转移代价是1

于是这样转转转就可以了,再考虑到总共有奇数个点的情况,答案为(n+1)/2-1

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<cmath>
 6 using namespace std;
 7 int read(){
 8     int x=0,f=1;char ch=getchar();
 9     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
10     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
11     return x*f;
12 }
13 int main(){
14     int i,j;
15     int n=read();
16     if(n==1)printf("0\n");
17     else{
18         printf("%d\n",(n+1)/2-1);
19     }
20     return 0;
21 }
C

相关文章: