标签:tin not lse can exist let alt ike end
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).
OutputPrint single integer — the last digit of 1378n.
Examples1
8
2
4
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==0) printf("1\n"); else if(n%4==1) { printf("8\n"); } else if(n%4==2) { printf("4\n"); } else if(n%4==3) { printf("2\n"); } else { printf("6\n"); } return 0; }
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.
OutputPrint single integer — the minimum cost Vladik has to pay to get to the olympiad.
Examples4 1 4
1010
1
5 5 2
10110
0
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.
1 #include<stdio.h> 2 int main() 3 { 4 int n,a,b; 5 char s[100010]; 6 scanf("%d %d %d",&n,&a,&b); 7 scanf("%s",s); 8 if(s[a-1]==s[b-1]) 9 printf("0\n"); 10 else 11 printf("1\n"); 12 return 0; 13 }
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).
OutputPrint single integer — the integer at the k-th position in the obtained sequence.
Examples3 2
2
4 8
4
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.
1 #include<bits/stdc++.h> 2 using namespace std; 3 long long n,k; 4 int main() 5 { 6 scanf("%lld%lld",&n,&k); 7 cout<<log2(k&(-k))+1<<endl; 8 }
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).
OutputIf 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.
Examples3
2 7 42
7
7 8 56
1 #include<stdio.h> 2 int main() 3 { 4 int n; 5 scanf("%d",&n); 6 if(n==1)printf("-1\n"); 7 else printf("%d %d %d\n",n,n+1,n*(n+1)); 8 return 0; 9 }
标签:tin not lse can exist let alt ike end
原文地址:https://www.cnblogs.com/weixq351/p/9367439.html