Codeforces Round #275 (Div. 2)

Source: Internet
Author: User

Link: http://codeforces.com/contest/485


A. Factorytime limit per test1 secondmemory limit per test256 megabytes

One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there wereXDetails in the factory storage, then by the end of the day the factory has to produce (remainder after dividingXByM) More details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.

The board of directors are worried that the production by the given plan may eventually stop (that means that there will be executed moment when the current number of details on the factory is divisibleM).

Given the number of detailsAOn the first day and numberMCheck if the production stops at some moment.

Input

The first line contains two integersAAndM(1? ≤?A,?M? ≤? 105 ).

Output

Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No ".

Sample test (s) Input
1 5
Output
No
Input
3 6
Output
Yes


X adds the modulo value for m each time. If the modulo value is 0, YES is output. If the modulo value has appeared before, No is output and No is exited.


# Include <cstdio> # include <cstring> int vis [100002]; int main () {int a, m; scanf ("% d", &, & m); memset (vis, 0, sizeof (vis); while (true) {if (a = 0) {printf ("Yes \ n "); return 0;} if (vis [a]) {printf ("No \ n"); return 0;} vis [a] = 1; a = (a + a % m) % m ;}}





B. Valuable ResourcesTime limit per test1 secondmemory limit per test256 megabytes

Compute computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.

Let's suppose that your task is to build a square city. the world map uses the Cartesian coordinates. the sides of the city shocould be parallel to coordinate axes. the map contains mines with valuable resources, located at some points with integer coordinates. the sizes of mines are relatively small, I. e. they can be treated as points. the city shoshould be built in such a way that all the mines are inside or on the border of the city square.

Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. given the positions of the mines find the minimum possible area of the city.

Input

The first line of the input contains numberN-The number of mines on the map (2? ≤?N? ≤? 1000). Each of the nextNLines contains a pair of integersXIAndYI-The coordinates of the corresponding mine (? -? 109? ≤?XI,?YI? ≤? 109). All points are pairwise distinct.

Output

Print the minimum area of the city that can cover all the mines with valuable resources.

Sample test (s) Input
20 02 2
Output
4
Input
20 00 3
Output
9


For a few vertices, place these vertices on or inside a square, and calculate the minimum value of the square area. The top minus the bottom and the rightmost minus the leftmost value is used as the edge length.


# Include <cstdio> # include <algorithm> # define ll long longusing namespace std; int main () {int n; ll x, y; ll mu, md, ml, mr; ll ans = 0; mu = mr =-2147483646; ml = md = 2147483647; scanf ("% d", & n); for (int I = 0; I <n; I ++) {scanf ("% I64d % I64d", & x, & y); mu = max (mu, y); md = min (md, y ); ml = min (ml, x); mr = max (mr, x);} ans = max (mu-md), (mr-ml )) * max (mu-md), (mr-ml); printf ("% I64d \ n", ans );}






C. BitsTime limit per test1 secondmemory limit per test256 megabytes

Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integerX.

You are given multiple queries consisting of pairs of integersLAndR. For each query, findX, Such thatL? ≤?X? ≤?R, And is maximum possible. If there are multiple such numbers find the smallest of them.

Input

The first line contains integerN-The number of queries (1? ≤?N? ≤? 10000 ).

Each of the followingNLines contain two integersLI,?RI-The arguments for the corresponding query (0? ≤?LI? ≤?RI? ≤? 1018 ).

Output

For each query print the answer in a separate line.

Sample test (s) Input
31 22 41 10
Output
137
Note

The binary representations of numbers from 1 to 10 are listed below:

110? =? 12

210? =? 102

310? =? 112

410? =? 1002

510? =? 1012

610? =? 1102

710? =? 1112

810? =? 10002

910? =? 10012

1010? =? 10102


For an interval, convert the number in the interval to the one with the largest number of '1' after being binary. If the number of '1' is the same, the minimum number is used to output the data.

Directly perform the OR operation on 1 from the left endpoint to construct the maximum and minimum number of '1' until the value is greater than the right endpoint.


# Include <cstdio> # define ll long longint main () {int t; scanf ("% d", & t); while (t --) {ll l, r, tmp, p = 1; scanf ("% I64d % I64d", & l, & r); for (ll I = 0; I <63; I ++) {ll tmp = l | p; if (tmp> r) break; l = tmp; p <= 1;} printf ("% I64d \ n ", l );}}





D. Maximum ValueTime limit per test1 secondmemory limit per test256 megabytes

You are given a sequenceAConsistingNIntegers. Find the maximum possible value of (integer remainderAIDividedAJ), Where1? ≤?I,?J? ≤?NAndAI? ≥?AJ.

Input

The first line contains integerN-The length of the sequence (1? ≤?N? ≤? 2 · 105 ).

The second line containsNSpace-separated integersAI(1? ≤?AI? ≤? 106 ).

Output

Print the answer to the problem.

Sample test (s) Input
33 4 5
Output
2


Find the maximum value of a [I] <a [j] a [j] % a [I]. The range of ai is small. Use hash to do this.


# Include <cstdio> int const MAX = 2000000 + 10; int a [MAX]; int main () {int n, x, ans = 0; scanf ("% d ", & n); for (int I = 0; I <n; I ++) {scanf ("% d", & x); a [x] = x ;} for (int I = 0; I <MAX; I ++) if (a [I]! = I) a [I] = a [I-1]; for (int I = 2; I <MAX; I ++) if (a [I] = I) for (int j = I + I-1; j <MAX; j = j + I) if (a [j] % I> ans & a [j]> I) ans = a [j] % I; printf ("% d \ n", ans );}





Div.1: D. KindergartenTime limit per test2 secondsmemory limit per test256 megabytes

In a kindergarten, the children are being divided into groups. the teacher put the children in a line and associated each child with his or her integer charisma value. each child shoshould go to exactly one group. each group shoshould be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particle, if the group consists of one child, its sociability equals a zero ).

The teacher wants to divide the children into some number of groups in such way that the totalsociability of the groups is maximum. Help him find this value.

Input

The first line contains integerN-The number of children in the line (1? ≤?N? ≤? 106 ).

The second line containsNIntegersAI-The charisma ofI-Th child (? -? 109? ≤?AI? ≤? 109 ).

Output

Print the maximum possible total sociability of all groups.

Sample test (s) Input
51 2 3 1 2
Output
3
Input
33 3 3
Output
0
Note

In the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1.

In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group.


Divides a series into several groups. The weight of each group is the difference between the maximum value and the minimum value in the group.


# Include <cstdio> # define ll long longint main () {int n, t; scanf ("% d", & n); ll ans = 0, t1 = 0, t2 = 0; for (int I = 0; I <n; I ++) {scanf ("% d", & t); if (! I | ans + t> t1) t1 = ans + t; if (! I | ans-t> t2) t2 = ans-t; ans = t1-t> t2 + t? T1-t: t2 + t;} printf ("% I64d \ n", ans );}



Codeforces Round #275 (Div. 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.