ACM 第三天
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
The single line of input contains one integer n (0 ≤ n ≤ 109).
Output
Print single integer — the last digit of 1378n.
Examples
1
8
2
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378·1378 = 1898884 is 4.
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n==)
printf("1\n");
else if(n%==)
{
printf("8\n");
}
else if(n%==)
{
printf("4\n");
}
else if(n%==)
{
printf("2\n");
}
else
{
printf("6\n");
}
return ;
}
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) —
the number of airports, the id of the airport from which Vladik starts
his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
Examples
4 1 4
1010
1
5 5 2
10110
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
#include<stdio.h>
int main()
{
int n,a,b;
char s[];
scanf("%d %d %d",&n,&a,&b);
scanf("%s",s);
if(s[a-]==s[b-])
printf("0\n");
else
printf("1\n");
return ;
}
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (n - 1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1, 2, 1] after the first step, the sequence [1, 2, 1, 3, 1, 2, 1] after the second step.
The task is to find the value of the element with index k (the elements are numbered from 1) in the obtained sequence, i. e. after (n - 1) steps.
Please help Chloe to solve the problem!
The only line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n - 1).
Output
Print single integer — the integer at the k-th position in the obtained sequence.
Examples
3 2
2
4 8
4
Note
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.
#include<bits/stdc++.h>
using namespace std;
long long n,k;
int main()
{
scanf("%lld%lld",&n,&k);
cout<<log2(k&(-k))+<<endl;
}
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .
Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding 109.
If there is no such answer, print -1.
The single line contains single integer n (1 ≤ n ≤ 104).
Output
If the answer exists, print 3 distinct numbers x, y and z (1 ≤ x, y, z ≤ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1.
If there are multiple answers, print any of them.
Examples
3
2 7 42
7
7 8 56
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n==)printf("-1\n");
else printf("%d %d %d\n",n,n+,n*(n+));
return ;
}
ACM 第三天的更多相关文章
- 【ACM】三点顺序
三点顺序 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 现在给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,现在让你判断A,B,C是顺时针给出的还是逆 ...
- 寒假的ACM训练三(PC110107/UVa10196)
#include <iostream> #include <string.h> using namespace std; char qp[10][10]; int result ...
- ACM第三次比赛 Big Chocolate
Problem G Big Chocolate Mohammad has recently visited Switzerland . As he loves his friends very muc ...
- ACM第三次比赛UVA11877 The Coco-Cola Store
Once upon a time, there is a special coco-cola store. If you return three empty bottles to the sho ...
- ACM第三题 完美立方
形如a3= b3 + c3 + d3的等式被称为完美立方等式.例如123= 63 + 83 + 103 .编写一个程序,对任给的正整数N (N≤100),寻找所有的四元组(a, b, c, d),使得 ...
- 今天的第一个程序-南阳acm输入三个数排序
#include<stdio.h>main(){ int a,b,c,t; scanf("%d%d%d",&a,&b,&c); ...
- (转)女生应该找一个玩ACM的男生
1.强烈的事业心 将来,他也一定会有自己热爱的事业.而且,男人最性感的时刻之一,就是他专心致志做事的时候.所以,找一个机会在他全神贯注玩ACM的时候,从侧面好好观察他,你就会发现我说的话没错. 2.永 ...
- ACM心情总结
已经快要12点了,然而还有5000字概率论论文没有动.在论文里,我本来是想要总结一下ACM竞赛中出现过的概率论题目,然而当敲打第一段前言的时候,我就迟疑了. 我问自己,ACM竞赛到底有什么现实意义. ...
- 【ACMER纷纷表示】女生应该找一个玩ACM的男生
1.强烈的事业心 将来,他也一定会有自己热爱的事业.而且,男人最性感的时刻之一,就是他专心致志做事的时候.所以,找一个机会在他全神贯注玩ACM的时候,从侧面好好观察他,你就会发现我说的话没错.2.永不 ...
随机推荐
- Linux入门——vsftpd
vsftpd Introduction vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小巧轻快,安全易用. vsftpd 的名字代表"very secure FTP ...
- (待整理)flume操作----------hivelogsToHDFS案例----------运行时,发生NoClassDefFoundError错误
1. 2.错误日志 命令为 bin/flume-ng agent --name a2 --conf conf/ --conf-file job/file-hdfs.conf Info: Sourcin ...
- linux内核中的IS_ERR()、PTR_ERR()、ERR_PTR()
IS_ERR宏定义在include/linux/err.h,如下所示: #define MAX_ERRNO 4095 //判断x是不是在(0xfffff000,0xffffffff)之间,注意这里用u ...
- ecshop跨站漏洞详情及修补网站漏洞
ecshop目前最新版本为4.0,是国内开源的一套商城系统,很多外贸公司,以及电商平台都在使用,正因为使用的人数较多,很多攻击者都在挖掘该网站的漏洞,就在最近ecshop被爆出高危漏洞,该漏洞利用跨站 ...
- java对象转map
/** * java对象转map * @param obj * @return * @throws IllegalAccessException * @throws IllegalArgumentEx ...
- MCUXpresso release build 时提示GFLIB等函数未引用的问题
MCUXpresso release build 时提示 GFLIB 等函数未引用的问题 最近在使用 MCUXpresso 编译工程时选择 Debug(Debug build) 能顺利编译,但是选择 ...
- error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
使用jetson tx2安装tensorpack时报错: error: command 'aarch64-linux-gnu-gcc' failed with exit status 1 改正: 如果 ...
- BZOJ1924_所驼门王的宝藏_KEY
题目传送门 这道题苟了我好久,因为链表的内存问题,之后再细讲. 首先这是一道Tarjan+DAG上DP的题目. 有三种门,对于每种门可以和其他门相连.即连边. 使用链表快速查询连边. 建完图后可以进行 ...
- 北京Uber优步司机奖励政策(1月28日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 《C++ Primer》第II部分:C++标准库
<C++ Primer>第II部分:C++标准库 前言 把<C++ Primer>读薄系列笔记.本篇为第II部分C++标准库,包含全书第8-12章重难点: IO库 顺序容器 范 ...