Imp is watching a documentary about cave painting.
![](https://i-blog.csdnimg.cn/blog_migrate/b77f28d565ac5363d8b9668de15d6e1c.png)
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.
Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that:
- 1 ≤ i < j ≤ k,
, where
is the remainder of division x by y.
The only line contains two integers n, k (1 ≤ n, k ≤ 1018).
Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper).
4 4
No
5 3
Yes
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
inline ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
const int maxn = 10000;
int main(){
ll n, k;
cin>>n>>k; unsigned ll lcmv=1;
if (k >= 43) {puts("No");return 0;}
for (int i=1; i<=k; i++){
lcmv = lcm(lcmv, i);
if ((n+1)%lcmv){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
}
Pushok the dog has been chasing Imp for a few hours already.
![](https://i-blog.csdnimg.cn/blog_migrate/15286d3d3176bc0eb4f37ca5b67169c4.png)
Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner.
While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of string "sh" as a subsequence in it, in other words, the number of such pairs (i, j), that i < j and and
.
The robot is off at the moment. Imp knows that it has a sequence of strings ti in its memory, and he can arbitrary change their order. When the robot is started, it generates the string t as a concatenation of these strings in the given order. The noise of the resulting string equals the noise of this concatenation.
Help Imp to find the maximum noise he can achieve by changing the order of the strings.
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of strings in robot's memory.
Next n lines contain the strings t1, t2, ..., tn, one per line. It is guaranteed that the strings are non-empty, contain only English letters 's' and 'h' and their total length does not exceed 105.
Print a single integer — the maxumum possible noise Imp can achieve by changing the order of the strings.
4 ssh hs s hhhs
18
2 h s
1
The optimal concatenation in the first sample is ssshhshhhs.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> ii;
struct myst
{
ll scnt, hcnt;
string st;
bool operator<(myst& rhs) const {
return (scnt * rhs.hcnt > rhs.scnt * hcnt);
}
}st[100000];
int main(){
ll n, t, len, scnt, hcnt, toth = 0;
ll cnt =0;
string tmp;
cin>> n;
for (ll i=0; i<n; i++){
cin>>tmp;
len = tmp.length();
hcnt = scnt = 0;
for (ll j=0; j<len; j++){
if (tmp[j] == 's') scnt++;
if (tmp[j] == 'h') hcnt++;
}
st[i] = {scnt, hcnt, tmp};
}
sort(st, st + n);
tmp = "";
for (ll i=0; i<n; i++){
//cout<<st[i].st<<endl;
tmp += st[i].st;
}
//cout<<tmp<<endl;
len = tmp.length();
for (ll i=0; i<tmp.length(); i++){
if (tmp[i] == 'h') toth++;
}
for (ll i=0; i<tmp.length(); i++){
if (tmp[i] == 's') cnt+=toth;
if (tmp[i] == 'h') toth--;
}
cout<<cnt<<endl;
}