#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&m,&n);
if(n<=0||m<0)
{
printf("No\n");
return 0;
}
if(n==1&&m!=0)
{
printf("No\n");
return 0;
}
if(m<n-1)
{
printf("No\n");
return 0;
}
if((m-n+1)%2==0)
printf("Yes\n");
else
printf("No\n");
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
int cnt[2600];
int sum[2600];
int main()
{
for(int i=1;i<=2500;i++)
for(int j=1;j<=i;j++)
{
int k=(i^j);
if(k<=0)
continue;
if(k<=j&&j+k>i)
{
cnt[i]++;
}
else
continue;
}
sum[1]=0;
for(int i=1;i<=2500;i++)
{
sum[i]=sum[i-1]+cnt[i];
}
int n;
while(~scanf("%d",&n))
{
printf("%d\n",sum[n]);
}
return 0;
}
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
In the first sample remainders modulo 1 and 4 coincide.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
ll n,m;
scanf("%I64d%I64d",&n,&m);
for(int i=1;i<=m;i++)
{
if(n%i!=(i-1))
{
printf("No\n");
return 0;
}
}
printf("Yes\n");
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
Note
The optimal concatenation in the first sample is ssshhshhhs.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1e5+10;
struct Str
{
string s;
double cnt;
}S[maxn];
static bool cmp(const Str& str1,const Str& str2)
{
return str1.cnt>str2.cnt;
}
string findSmallest(Str S[], int n)
{
string str = "";
sort(S+1,S+n+1,cmp);
for (int i=1;i<=n; ++i)
str+=S[i].s;
return str;
}
int main()
{
int n;
string N;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
cin>>S[i].s;
}
for(int i=1;i<=n;i++)
{
int is=0,ih=0;
for(int j=0;S[i].s[j]!='\0';j++)
{
if(S[i].s[j]=='s')
is++;
else
ih++;
}
if(ih==0)
S[i].cnt=INF;
else
S[i].cnt=(double)is/double(ih);
}
N=findSmallest(S,n);
int s=0,h=0;
if(N[0]=='s')
s++;
else
h++;
ll sum=0;
for(int i=1;N[i]!='\0';i++)
{
if(N[i]=='s')
s++;
else
{
h++;
sum+=s;
}
}
printf("%I64d\n",sum);
return 0;
}