Round #411 (Div.2)
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.
The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
19 29
2
3 6
3
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}.
题意:求因子
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main(){ 4 int l,r; 5 scanf("%d%d",&l,&r); 6 if(l==r) printf("%d\n",l); 7 else printf("2\n"); 8 9 }
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Print the minimum number of steps modulo 109 + 7.
ab
1
aab
3
The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa".
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int mod=1e9+7; 4 int main(){ 5 string s; 6 cin>>s; 7 int ans=0; 8 int t=0; 9 for(int i=s.length()-1;i>=0;i--){ 10 if(s[i]=='b') 11 t=(t+1)%mod; 12 else { 13 ans=(ans+t)%mod; 14 t=(t*2)%mod; 15 } 16 } 17 cout<<ans<<endl; 18 return 0; 19 }