A. Counterexample
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.

Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.

You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r.

More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair(a, c) is not coprime.

Input

The single line contains two positive space-separated integers lr (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).

Output

Print three positive space-separated integers abc — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.

If the counterexample does not exist, print the single number -1.

Examples
input
2 4
output
2 3 4
input
10 11
output
-1
input
900000000000000009 900000000000000029
output
900000000000000009 900000000000000010 900000000000000021
Note

In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.

In the second sample you cannot form a group of three distinct integers, so the answer is -1.

In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.

暴力;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x,y) cout<<"bug"<<x<<" "<<y<<endl;
#define bug(x) cout<<"xxx "<<x<<endl;
const int N=1e5+,M=1e6+,inf=2e9+,mod=;
const ll INF=1e18+;
int main()
{
ll l,r;
scanf("%lld%lld",&l,&r);
for(ll i=l;i<=r;i++)
{
for(ll j=i+;j<=r;j++)
{
for(ll k=j+;k<=r;k++)
{
if(i==j||i==k||j==k)continue;
if(__gcd(i,j)==&&__gcd(j,k)==&&__gcd(i,k)!=)
return *printf("%lld %lld %lld\n",i,j,k);
}
}
}
printf("-1\n");
return ;
}
B. Friends and Presents
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.

In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.

Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.

A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.

Input

The only line contains four positive integers cnt1, cnt2, xy (1 ≤ cnt1, cnt2 < 109; cnt1 + cnt2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers xy are prime.

Output

Print a single integer — the answer to the problem.

Examples
input
3 1 2 3
output
5
input
1 3 2 3
output
4
Note

In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.

In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.

题意:第一个人需要cnt1个数,并且每个数都不被x整除,第二个人需要cnt2个数,并且每个数都不被y整除;

    求最小的v,使得1-v,v个数可以使得两个都能拿到各自数目的数;

思路:二分v即可,主要在于check怎么写;

    有点类似容斥的原理,先把两个都不能放的去掉,然后将不能放2的尽量放1 ,不能放1 的尽量放2;

   然后把v剩余与cnt1,cnt2剩余比较;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x,y) cout<<"bug"<<x<<" "<<y<<endl;
#define bug(x) cout<<"xxx "<<x<<endl;
const int N=1e5+,M=1e6+,inf=2e9+,mod=;
const ll INF=1e18+;
ll check(ll x,ll a,ll b,ll cnt1,ll cnt2)
{
ll p=x/a;
ll q=x/b;
ll c=x/(a*b/__gcd(a,b));
p-=c;
q-=c;
cnt1-=min(cnt1,q);
cnt2-=min(cnt2,p);
return x-c-p-q>=cnt2+cnt1;
}
int main()
{
ll cnt1,cnt2,x,y;
scanf("%lld%lld%lld%lld",&cnt1,&cnt2,&x,&y);
ll l=;
ll r=1e10,ans;
while(l<=r)
{
ll mid=(l+r)>>;
if(check(mid,x,y,cnt1,cnt2))
{
r=mid-;
ans=mid;
}
else l=mid+;
}
printf("%lld\n",ans);
return ;
}
C. Diverse Permutation
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive integers not larger than n. We'll denote as nthe length of permutation p1,   p2,   ...,   pn.

Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.

Input

The single line of the input contains two space-separated positive integers nk (1 ≤ k < n ≤ 105).

Output

Print n integers forming the permutation. If there are multiple answers, print any of them.

Examples
input
3 2
output
1 3 2
input
3 1
output
1 2 3
input
5 2
output
1 3 2 4 5
Note

By |x| we denote the absolute value of number x.

题意:n个数1-n,随意排放,两两相差为x,使得x的不同的数目为K;

思路:构造思路题,1 n  2  n-1 构造k-1个,后面递增,递减差值都为1 即可;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x,y) cout<<"bug"<<x<<" "<<y<<endl;
#define bug(x) cout<<"xxx "<<x<<endl;
const int N=1e5+,M=1e6+,inf=2e9+,mod=;
const ll INF=1e18+;
int main()
{
int n,k;
scanf("%d%d",&n,&k);
int l=,r=n,last=;
for(int i=;i<=k;i++)
{
if(i&)printf("%d ",l++),last=;
else printf("%d ",r--),last=;
}
if(last)for(int i=l;i<=r;i++)printf("%d ",i);
else for(int i=r;i>=l;i--)printf("%d ",i);
return ;
}
D. Interesting Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers liriqi (1 ≤ li ≤ ri ≤ n) meaning that value  should be equal to qi.

Your task is to find any interesting array of n elements or state that such array doesn't exist.

Expression x&y means the bitwise AND of numbers x and y. In programming languages C++, Java and Python this operation is represented as "&", in Pascal — as "and".

Input

The first line contains two integers nm (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits.

Each of the next m lines contains three integers liriqi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit.

Output

If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n](0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them.

If the interesting array doesn't exist, print "NO" (without the quotes) in the single line.

Examples
input
3 1
1 3 3
output
YES
3 3 3
input
3 2
1 3 3
1 3 2
output
NO

思路:线段数区间并;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x,y) cout<<"bug"<<x<<" "<<y<<endl;
#define bug(x) cout<<"xxx "<<x<<endl;
const int N=1e5+,M=1e6+,inf=2e9+,mod=;
const ll INF=1e18+;
struct linetree
{
int sum[N<<],lazy[N<<];
void pushup(int pos)
{
sum[pos]=sum[pos<<]&sum[pos<<|];
}
void pushdown(int pos)
{
if(lazy[pos])
{
sum[pos<<]|=lazy[pos];
sum[pos<<|]|=lazy[pos];
lazy[pos<<]|=lazy[pos];
lazy[pos<<|]|=lazy[pos];
lazy[pos]=;
}
}
void build(int l,int r,int pos)
{
lazy[pos]=;
if(l==r)
{
sum[pos]=;
return;
}
int mid=(l+r)>>;
build(l,mid,pos<<);
build(mid+,r,pos<<|);
pushup(pos);
}
void update(int L,int R,int c,int l,int r,int pos)
{
if(L<=l&&r<=R)
{
sum[pos]|=c;
lazy[pos]|=c;
return;
}
pushdown(pos);
int mid=(l+r)>>;
if(L<=mid)
update(L,R,c,l,mid,pos<<);
if(R>mid)
update(L,R,c,mid+,r,pos<<|);
pushup(pos);
}
int query(int L,int R,int l,int r,int pos)
{
if(L<=l&&r<=R)
return sum[pos];
pushdown(pos);
int mid=(l+r)>>;
int ans=((<<)-);
if(L<=mid)
ans&=query(L,R,l,mid,pos<<);
if(R>mid)
ans&=query(L,R,mid+,r,pos<<|);
return ans;
}
};
linetree tree;
int l[N],r[N],x[N];
int main()
{
int n,q,ans=;
scanf("%d%d",&n,&q);
for(int i=;i<=q;i++)
{
scanf("%d%d%d",&l[i],&r[i],&x[i]);
tree.update(l[i],r[i],x[i],,n,);
if(tree.query(l[i],r[i],,n,)!=x[i])
ans=;
}
for(int i=;i<=q;i++)
if(tree.query(l[i],r[i],,n,)!=x[i])
ans=;
if(!ans)
printf("NO\n");
else
{
printf("YES\n");
for(int i=;i<=n;i++)
{
int out=tree.query(i,i,,n,);
printf("%d ",out);
}
}
return ;
}
A. Counterexample
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.

Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.

You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r.

More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair(a, c) is not coprime.

Input

The single line contains two positive space-separated integers lr (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).

Output

Print three positive space-separated integers abc — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.

If the counterexample does not exist, print the single number -1.

Examples
input
2 4
output
2 3 4
input
10 11
output
-1
input
900000000000000009 900000000000000029
output
900000000000000009 900000000000000010 900000000000000021
Note

In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.

In the second sample you cannot form a group of three distinct integers, so the answer is -1.

In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.

Codeforces Round #275 (Div. 2) A,B,C,D的更多相关文章

  1. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  2. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  3. 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

    题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...

  4. [Codeforces Round #275 (Div. 2)]B - Friends and Presents

    最近一直在做 codeforces ,总觉得已经刷不动 BZOJ 了? ——真是弱喵 你看连 Div.2 的 B 题都要谢谢题解,不是闲就是傻 显然我没那么闲 ╮(╯_╰)╭ 我觉得这题的想法挺妙的~ ...

  5. Codeforces Round #275 (Div. 2) C

    题目传送门:http://codeforces.com/contest/483/problem/C 题意分析:题目意思没啥好说的. 去搞排列列举必须TLE.那么就想到构造. 1.n.2.n-1.3.n ...

  6. Codeforces Round #275(Div. 2)-C. Diverse Permutation

    http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...

  7. Codeforces Round #275 (Div. 2)-A. Counterexample

    http://codeforces.com/contest/483/problem/A A. Counterexample time limit per test 1 second memory li ...

  8. Codeforces Round #275 Div.1 B Interesting Array --线段树

    题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...

  9. Codeforces Round #275 (Div. 2)

    A. Counterexample 题意:给出l,r,找出使得满足l<a<b<c<r,同时满足a,b的最大公约数为1,b,c的最大公约数为1,且a,b的最大公约数不为1 因为题 ...

  10. Codeforces Round #275 (Div. 2) 题解

    A 题: 说的是在(LR) 之间找出ab互质 bc 互质 ac 不互质的 3个数 数据量小直接暴力 #include <iostream> #include <cstdio> ...

随机推荐

  1. SaltStack配置管理-jinja模板

    上一篇:SaltStack配置管理-状态间关系 需求:需要apache配置文件里面监听的端口是每个minion本地的地址 saltstack默认的模板是jinjia模板 参考文档:http://doc ...

  2. Oracle AWR之-enq: TX - allocate ITL entry

    今天收到压力测试期间awr报告,测试人员要我看看数据库是否有可以优化的地方,数据库服务器配置信息:CPU:32*8,内存:480g 单实例数据库:oracle 11.2.0.4.具体分析过程如下: 可 ...

  3. 点击劫持漏洞解决( Clickjacking: X-Frame-Options header missing)

    点击劫持漏洞 X-Frame-Options HTTP 响应头, 可以指示浏览器是否应该加载一个 iframe 中的页面. 网站可以通过设置 X-Frame-Options 阻止站点内的页面被其他页面 ...

  4. Feed系统架构资料收集(转)

    add by zhj:有些链接已经失效,后续会修改. 原文:http://blog.csdn.net/zhangzhaokun/article/details/7834797 完全用nosql轻松打造 ...

  5. day11(jsp入门&Cookie&HttpSession&一次性图片校验码)

    day11 JSP入门   1 JSP概述 1.1 什么是JSP JSP(Java Server Pages)是JavaWeb服务器端的动态资源.它与html页面的作用是相同的,显示数据和获取数据. ...

  6. 锁、volatile、CAS 比较

    一.锁的劣势 (1) 在JDK1.5之前都是使用synchronized关键字保证同步的,这种通过使用一致的锁定协议来协调对共享状态的访问,可以确保无论哪个线程持有守 护变量的锁,都采用独占的方式来访 ...

  7. python pip源配置

    一.Linux版本: linux的文件存放在:~/.pip/pip.conf 二.windows版本: 在用户文件夹下创建pip目录,并在pip目录下创建pip.ini文件(%HOME%\pip\pi ...

  8. HTML---初识HTML

    版权声明:本文为博主原创文章.不经博主同意注明链接就可以转载. https://blog.csdn.net/Senior_lee/article/details/33723573          H ...

  9. loadNibNamed:(NSString *)name owner:(nullable id)owner options:(nullable NSDictionary *)options用法

    1.name xib的名字 owner当前类对象 options初始参数 实际应用: NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@&quo ...

  10. Redis持久化磁盘IO方式及其带来的问题

    有Redis线上运维经验的人会发现Redis在物理内存使用比较多,但还没有超过实际物理内存总容量时就会发生不稳定甚至崩溃的问题 一.对Redis持久化的探讨与理解 redis是一个支持持久化的内存数据 ...