Você está na página 1de 33

7974.

Whats Next
Problem code: ACPC10A
According to Wikipedia, an arithmetic progression (AP) is a sequence of numbers such that the difference of any two successive members of the sequence is a constant. For instance, the sequence 3, 5, 7, 9, 11, 13, . . . is an arithmetic progression with common difference 2. For this problem, we will limit ourselves to arithmetic progression whose common difference is a non-zero integer. On the other hand, a geometric progression (GP) is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, . . . is a geometric progression with common ratio 3. For this problem, we will limit ourselves to geometric progression whose common ratio is a non-zero integer. Given three successive members of a sequence, you need to determine the type of the progression and the next successive member.

Input
Your program will be tested on one or more test cases. Each case is specified on a single line with three integers (10, 000 < a1 , a2 , a3 < 10, 000) where a1 , a2 , and a3 are distinct. The last case is followed by a line with three zeros.

Output
For each test case, you program must print a single line of the form: XX v where XX is either AP or GP depending if the given progression is an Arithmetic or Geometric Progression. v is the next member of the given sequence. All input cases are guaranteed to be either an arithmetic or geometric progressions.

Example
Input: 4 7 10 2 6 18 0 0 0 Output: AP 13 GP 54 Added by: Date: Time limit: Source limit: Languages: Resource: Omar ElAzazy 2010-11-30 2s 50000B All ACPC 2010

Lang=c++-4.3.2

8057. Square Free Factorization


Problem code: AMR10C
You all know about factorization of an integer. Here we want you to factor a number into as few factors as possible. That is easy, you say, just have the number itself, and that will be the smallest number of factors i.e. 1. But wait, I haven't finished -- each of the factors that you find must be square-free. A square-free number, however you factor it, won't have any factor that is a perfect square. Of course, you can never include 1 as a factor. INPUT The first line The next OUTPUT For each of T input lines output the is the each smallest <= N number have number of an of test cases integer square-free T. N.

testcase,

factors. 1e4 1e6 INPUT

CONSTRAINTS T 2 SAMPLE 2 6 8 SAMPLE 1 3

<=

<=

OUTPUT

Added by: Date: Time limit: Source limit: Languages: Resource:

Varun Jalan 2010-12-13 3s 50000B All own problem, ICPC Asia regionals, Amritapuri 2010

8001. Fibonacci Sum


Problem code: FIBOSUM
The fibonacci sequence is defined by the following relation: F(0) = 0

F(1) = 1 F(N) = F(N - 1) + F(N - 2), N >= 2

Your task is very simple. Given two non-negative integers N and M, you have to calculate the sum (F(N) + F(N + 1) + ... + F(M)) mod 1000000007.

Input
The

rst line contains an integer T (the number of test cases). Then, T lines follow. Each test case consists of a single line with two non-negative integers N and M.

The

first line contains an integer T (the number of test cases). Then, T lines follow. Each test case consists of a single line with two non-negative integers N and M.

Output
For each test case you have to output a single line containing the answer for the task.

Example
Input: 3 0 3 3 5 10 19 Output: 4 10 10857

Constraints
T <= 1000 0 <= N <= M <= 109

Added by: Date: Time limit: Source limit: Languages: Resource:

David Gmez 201012-04 5s 50000B All My Own

Lang=C

3407. Candy
Problem code: SAMER08C
Little Charlie is a nice boy addicted to candies. He is even a subscriber to All Candies Magazine and was selected to participate in the International Candy Picking Contest. In this contest a random number of boxes containing candies are disposed in M rows with N columns each (so, there are a total of M N boxes). Each box has a number indicating how many candies it contains. The contestant can pick a box (any one) and get all the candies it contains. But

there is a catch (there is always a the rows immediately above and box to the left and the box to continues to pick a box until there

catch): when choosing a box, all the boxes from immediately below are emptied, as well as the the right of the chosen box. The contestant are no candies left.

The figure bellow illustrates this, step by step. Each cell represents one box and the number of candies it contains. At each step, the chosen box is circled and the shaded cells represent the boxes that will be emptied. After eight steps the game is over and Charlie picked 10+9+8+3+7+6+10+1 = 54 candies.

For small values of M and N, Charlie can easily find the maximum number of candies he can pick, but when the numbers are really large he gets completely lost. Can you help Charlie maximize the number of candies he can pick?

Input
The input contains several test cases. The first line of a test case contains two positive integers M and N (1 M N 105), separated by a single space, indicating the number of rows and columns respectively. Each of the following M lines contains N integers separated by single spaces, each representing the initial number of candies in the corresponding box. Each box will have initially at least 1 and at most 103 candies. The end of input is indicated by a line containing two zeroes separated by a single space.

Output
For each test case in the input, your program must print a single line, containing a single value, the integer indicating the maximum number of candies that Charlie can pick.

Example
Input:

5 5 1 8 2 1 9 1 7 3 5 2 1 2 10 3 10 8 4 7 9 1 7 1 3 1 6 4 4 10 1 1 10 1 1 1 1 1 1 1 1 10 1 1 10 2 4 9 10 2 7 5 1 1 5 0 0 Output: 54 40 17

Added by: Date: Time limit: Source limit: Languages: Resource:

Diego Satoba 2008-11-23 2s 50000B C C++ 4.3.2 C++ 4.0.0-8 JAVA PAS fpc PAS gpc South American Regional Contests 2008

Lang=c++4.0.0-8

3410. Feynman
Problem code: SAMER08F
Richard Phillips Feynman was a well known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and also pioneered the field of quantum computing. He visited South America for ten months, giving lectures and enjoying life in the tropics. He is also known for his books "Surely You're Joking, Mr. Feynman!" and "What Do You Care What Other People Think?", which include some of his adventures below the equator. His life-long addiction was solving and making puzzles, locks, and cyphers. Recently, an old farmer in South America, who was a host to the young physicist in 1949, found some papers and notes that is believed to have belonged to Feynman. Among notes about mesons and electromagnetism, there was a napkin where he wrote a simple puzzle: "how many different squares are there in a grid of N N squares?". In the same napkin there was a drawing which is reproduced below, showing that, for N=2, the answer is 5.

Input
The input contains several test cases. Each test case is composed of a single line, containing only one integerN, representing the number of squares in each side of the grid (1 N 100). The end of input is indicated by a line containing only one zero.

Output
For each test case in the input, your program must print a single line, containing the number of different squares for the corresponding input.

Example
Input: 2 1 8 0 Output: 5 1 204

Added by: Date: Time limit: Source limit: Languages: Resource:

Diego Satoba 2008-11-23 1s 50000B C C++ 4.3.2 C++ 4.0.0-8 JAVA PAS fpc PAS gpc South American Regional Contests 2008

Lang=JAVA

1163. Java vs C ++
Problem code: JAVAC
Apologists of Java and C++ can argue for hours proving each other that their programming language is the best one. Java people will tell that their programs are clearer and less prone to errors, while C++ people will laugh at their inability to instantiate an array of generics or tell them that their programs are slow and have long source code.

Another issue that Java and C++ people could never agree on is identifier naming. In Java a multiword identifier is constructed in the following manner: the first word is written starting from the small letter, and the following ones are written starting from the capital letter, no separators are used. All other letters are small. Examples of a Java identifier are javaIdentifier, longAndMnemonicIdentifier, name, nEERC.

Unlike them, C++ people use only small letters in their identifiers. To separate words they use underscore character _. Examples of C++ identifiers are c_identifier, long_and_mnemonic_identifier, name (you see that when there is just one word Java and C++ people agree), n_e_e_r_c.

You are writing a translator that is intended to translate C++ programs to Java and vice versa. Of course, identifiers in the translated program must be formatted due to its language rules otherwise people will never like your translator.

The first thing you would like to write is an identifier translation routine. Given an identifier, it would detect whether it is Java identifier or C++ identifier and translate it to another dialect. If it is neither, then your routine should report an error. Translation must preserve the order of words and must only change the case of letters and/or add/remove underscores.

Input
The input file consists of several lines that contains an identifier. It consists of letters of the English alphabet and underscores. Its length does not exceed 100.

Output
If the input identifier is Java identifier, output its C++ version. If it is C++ identifier, output its Java version. If it is none, output 'Error!' instead.

Example
Input: long_and_mnemonic_identifier anotherExample i bad_Style Output: longAndMnemonicIdentifier another_example i Error! Added by: Camilo Andrs Varela Len

Date: Time limit: Source limit: Languages: Resource:

2006-12-14 1s 50000B All except: ERL JS PERL 6 Northeastern Europe 2006

language=c++4.0,0.0-8

1112. Number Steps


Problem code: NSTEPS
Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,... as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has continued.

You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...10000.

Input
The first line of the input is N, the number of test cases for this problem. In each of the N following lines, there is x, and y representing the coordinates (x, y) of a point.

Output
For each point in the input, write the number written at that point or write No Number if there is none.

Example
Input: 3 4 2 6 6 3 4 Output: 6 12 No Number Added by: Date: Time limit: Source limit: Languages: Resource: Camilo Andrs Varela Len 2006-11-25 2s 50000B All except: ERL JS PERL 6 Asia - Tehran 2000

language=C

302. Count on Cantor


Problem code: CANTON
One of the famous proofs of modern mathematics is Georg Cantor's demonstration that the set of rational numbers is enumerable. The proof works by using an explicit enumeration of rational numbers as shown in the diagram below. 1/1 2/1 3/1 4/1 5/1 1/2 1/3 1/4 1/5 ... 2/2 2/3 2/4 3/2 3/3 4/2

In the above diagram, the first term is 1/1, the second term is 1/2, the third term is 2/1, the fourth term is 3/1, the fifth term is 2/2, and so on.

Input
The input starts with a line containing a single integer t <= 20, the number of test cases. t test cases follow. Then, it contains a single number per line.

Output

You are to write a program that will read a list of numbers in the range from 1 to 10^7 and will print for each number the corresponding term in Cantor's enumeration as given below.

Example
Input: 3 3 14 7 Output: TERM 3 IS 2/1 TERM 14 IS 2/4 TERM 7 IS 1/4 Added by: Date: Time limit: Source limit: Languages: Resource: Thanh-Vy Hua 2005-02-27 5s 50000B All except: PERL 6 ACM South Eastern European Region 2004

language=C

1030. Triple Fat Ladies


Problem code: EIGHTS
Pattern Matchers have been designed for various sorts of patterns. Mr. HKP likes to observe patterns in numbers. After completing his extensive research on the squares of numbers, he has moved on to cubes. Now he wants to know all numbers whose cube ends in 888. Given a number k, help Mr. HKP find the kth number (indexed from 1) whose cube ends in 888.

Input
The first line of the input contains an integer t, the number of test cases. t test cases follow. Each test case consists of a single line containing a single integer k (1 <= k <= 2000000000000).

Output
For each test case, output a single integer which denotes the kth number whose cube ends in 888. The result will be less than 263.

Example
Input: 1 1 Output: 192

language=C++4.0.0-8

Added by: Date: Time limit: Source limit: Languages:

Matthew Reeder 2006-10-30 5s 30000B All except: ERL JS PERL 6 Al-Khawarizm 2006

1025. Fashion Shows


Problem code: FASHION
A fashion show rates participants according to their level of hotness. Two different fashion shows were organized, one for men and the other for women. A date for the third is yet to be decided ;) . Now the results of both fashion shows are out. The participants of both the fashion shows have decided to date each other, but as usual they have difficuly in choosing their partners. The Maximum Match dating serive (MMDS) comes to their rescue and matches them in such a way that that maximizes the hotness bonds for all couples. If a man has been rated at hotness level x and a women at hotness level y, the value of their hotness bond isx*y. Both fashion shows contain N participants each. MMDS has done its job and your job is to find the sum of hotness bonds for all the couples that MMDS has proposed. Resource:

Input
The first line of the input contains an integer t, the number of test cases. t test cases follow. Each test case consists of 3 lines: The first line contains a single integer N (1 <= N <= 1000). The second line contains N integers separated by single spaces denoting the hotness levels of the men. The third line contains N integers separated by single spaces denoting the hotness levels of the women.

All hotness ratings are on a scale of 0 to 10.

Output
For each test case output a single line containing a single integer denoting the sum of the hotness bonds for all pairs that MMDS has proposed.

Example

Input: 2 2 1 1 3 2 3 2 3 2 1 3 2 Output: 5 15 Added by: Date: Time limit: Source limit: Languages: Resource: Matthew Reeder 2006-10-29 2s 30000B All except: ERL JS PERL 6 Al-Khawarizm 2006

language=C

1786. In Danger
Problem code: DANGER
Flavius Josephus and 40 fellow rebels were trapped by the Romans. His companions preferred suicide to surrender, so they decided to form a circle and to kill every third person and to proceed around the circle until no one was left. Josephus was not excited by the idea of killing himself, so he calculated the position to be the last man standing (and then he did not commit suicide since nobody could watch). We will consider a variant of this "game" where every second person leaves. And of course there will be more than 41 persons, for we now have computers. You have to calculate the safe position. Be careful because we might apply your program to calculate the winner of this contest!

Input Specification
The input contains several test cases. Each specifies a number n, denoting the number of persons participating in the game. To make things more difficult, it always has the format "xyez" with the following semantics: when n is written down in decimal notation, its first digit is x, its second digit is y, and then followz zeros. Whereas 0<=x,y<=9, the number of zeros is 0<=z<=6. You may assume that n>0. The last test case is followed by the string 00e0.

Output Specification
For each test case generate a line containing the position of the person who survives. Assume that the participants have serial numbers from 1 to n and that the counting starts with person 1, i.e., the first person leaving is the one with number 2. For example, if there are 5 persons in the circle, counting proceeds as 2, 4, 1, 5 and person 3 is staying alive.

Sample Input
05e0 01e1 42e0 66e6 00e0

Sample Output
3 5 21 64891137 Added by: Date: Time limit: Source limit: Langua ges: Wanderley Guimares 2007-09-19 1s 50000B All except: ERL JS University of Ulm Local Contest 2004

1812. Longest Common Substring II


Problem code: LCS2
A string is finite sequence of characters over a non-empty finite set . In this problem, is the set of lowercase letters. Substring, also called factor, is a consecutive sequence of characters occurrences at least once in a string. Resourc Now your task is a bit harder, for some given strings, find the length of the longest common substring of e: them. Here common substring means a substring of two or more strings.

Input
The input contains at most 10 lines, each line consists of no more than 100000 lowercase letters, representing a string.

Output
The length of the longest common substring. If such string doesn't exist, print "0" instead.

Example
Input: alsdfkjfjkdsal fdjskalajfkdsla aaaajfaaaa Output: 2 Notice: new testcases added

Added by: Date: Time limit:

Bin Jin 2007-09-24 2s

Source limit: 50000B Languages: All except: C++ 4.0.0-8

10394. Buying Apples!


Problem code: ABA12C
Harish went to a supermarket to buy exactly k kilograms apples for his n friends. The supermarket was really weird. The pricing of items was very different. He went to the Apples section and enquired about the prices. The salesman gave him a card in which he found that the prices of apples were not per kg. The apples were packed into covers, each containing x kg of apples, x > 0 and x is an integer. An x kg packet would be valued at y rupees. So, the placard contained a table with an entry y denoting the price of an x kg packet. If y is -1 it means that the corresponding packet is not available. Now as apples are available only in packets, he decides to buy atmost n packets for his n friends i.e he will not buy more than n packets of apples. Harish likes his friends a lot and so he does not want to disappoint his friends. So now, he will tell you how many friends he has and you have to tell him the minimum amount of money he has to spend for his friends. Input The first line of input will contain the number of test cases, C. Each test case will contain two lines. The first line containing N and K, the number of friends he has and the amount of Apples in kilograms which he should buy. The second line contains K space separated integers in which the ith integer specifies the price of a ikg

apple packet. A value of -1 denotes that the corresponding packet is unavailable. 0 < N <= 100 0 < K <= 100 0 < price <= 1000 Output The output for each test case should be a single line containing the minimum amount of money he has to spend for his friends. Print -1 if it is not possible for him to satisfy his friends. Sample I/O: Input: 2 35 -1 -1 4 5 -1 55 12345 Output: -1 5 Explanation of test cases: 1) As there are only 3 and 4kg packets in the shop, he will not be able to satisfy his friends as he would not be able to buy exactly 5kg of apples. 2) He can buy five 1kg packet as he has to buy 5 kg. So the min money he should spend is 5.

Added by: Date: Time limit:

Kashyap 2012-01-13 1s

Source limit: 50000B

Languages: Resource:

All Own problem

2178. He is offside!
Problem code: OFFSIDE
Hemisphere Network is the largest television network in Tumbolia, a small country located east of South America (or south of East America). The most popular sport in Tumbolia, unsurprisingly, is soccer; many games are broadcast every week in Tumbolia. Hemisphere Network receives many requests to replay dubious plays; usually, these happen when a player is deemed to be offside by the referee. An attacking player is offside if he is nearer to his opponents goal line than the second last opponent. A player is not offside if he is level with the second last opponent or he is level with the last two opponents.

Through the use of computer graphics technology, Hemisphere Network can take an image of the field and determine the distances of the players to the defending teams goal line, but they still need a program that, given these distances, decides whether a player is offside.

Input
The input file contains several test cases. The first line of each test case contains two integers A and D separated by a single space indicating, respectively, the number of attacking and defending players involved in the play (2 <= A,D <= 11). The next line contains A integers Bi separated by single spaces, indicating the distances of the attacking players to the goal line (1 <= B i <= 104). The next line contains D integers Cjseparated by single spaces, indicating the distances of the defending players to the goal line (1 <= Cj <= 104). The end of input is indicated by A = D = 0.

Output
For each test case in the input print a line containing a single character: Y

(uppercase) if there is an attacking player offside, and N (uppercase) otherwise.

Example
Input: 2 3 500 700 700 500 500 2 2 200 400 200 1000 3 4 530 510 490 480 470 50 310 0 0 Output: N Y N

5917. Factorial length


Problem code: LENGFACT
Given integer n, print length of n! (which is factorial of n).

Input
The first line of the standard input contains one integer t (t<10001) which is the number of test cases. In each of the next t lines there is number n (0<=n<=5*10^9).

Output
For each test, print the length of n! (which is factorial of n).

Example
Input: 3 1 10 100 Output: 1 7 158 len(n!)=ceiling(log10(1)+log10(2)+.+log10(n))

numDigits(n!) = floor((ln(2*pi*n)/2+n*(ln(n)-1))/ln(10))+1 ---- correct

Added by: Date: Time limit: Source limit: Languages: Resource:

Piotr Kkol 2010-01-19 2s 50000B

All Copy of the problem: FACTLENG with different assessment

4549. Adding Sevens


Problem code: ANARC08B
A seven segment display, similar to the one shown on the right, is composed of seven light-emitting elements. Individually on or off, they can be combined to produce 127 different combinations, including the ten Arabic numerals. The figure below illustrates how the ten numerals are displayed. 7-seg displays (as they're often abbreviated) are widely used in digital clocks, electronic meters, and calculators.

A 7-seg has seven connectors, one for each element, (plus few more connectors for other electrical purposes.) Each element can be turned on by sending an electric current through its pin. Each of the seven pins is viewed by programmers as a single bit in a 7-bit number, as they are more comfortable dealing with bits rather than electrical signals. The figure below shows the bit assignment for a typical 7-seg, bit 0 being the right-most bit.

For example, in order to display the digit 1, the programmer knows that only bits 1 and 3 need to be on, i.e. the 7-bit binary number to display digit 1 is "0001010", or 10 in decimal. Let's call the decimal number for displaying a digit, its display code, or just code for short. Since a 7-seg displays 127 different configurations, display codes are normally written using 3 decimal places with leading zeros if necessary, i.e. the display code for digit 1 is written as 010. In a 9-digit calculator, 9 7-seg displays are stacked next to each other, and are all controlled by a single controller. The controller is sent a sequence of 3n digits, representing n display codes, where 0 < n < 10 . If n < 9 , the number is right justified and leading zeros are automatically displayed. For example, the display code for 13 is 010079 while for 144 it is 010106106 Write a program that reads the display codes of two numbers, and prints the display code of their sum.

Input
Your program will be tested on one or more test cases. Each test case is specified on a single line in the form of A+B= where both A and B are display codes for decimal numbers a and b respectively where 0 < a , b < a + b < 1, 000, 000, 000 . The last line of the input file is the word "BYE" (without the double quotes.)

Output
For each test case, print A+B=C where C is the display code for a + b .

Example
Input: 010079010+010079= 106010+010= BYE Output: 010079010+010079=010106106 106010+010=106093

Added by: Date: Time limit:

Ahmed Aly 2009-07-03 1s

Source limit: 50000B Languages: Resource: All except: ERL JS PERL 6 ANARC 2008

3866. Finding Palindromes


Problem code: VPALIN

A word is called a palindrome if we read from right to left is as same as we read from left to right. For example, "dad", "eye" and "racecar" are all palindromes, but "odd", "see" and "orange" are not palindromes. Given n palindromes, you can generate n n pairs of them and concatenate the pairs into single words. The task is to count how many of the so generated words are palindromes.

Input
The first line of input file contains the number of strings n. The following n lines describe each string: The i+1-th line contains the length of the i-th string li, then a single space and a string of li small letters of English alphabet. You can assume that the total length of all strings will not exceed 2,000,000. Two strings in different line may be the same.

Output
Print out only one integer, the number of palindromes.

Example
Input: 3 1 a 2 bb 2 aa Output: 5 The 5 palindromes are: aa aaa aaa bbb aaaa

Added by: Date: Time limit:

Phenomenal 2009-02-15 5s-7s

Source limit: 50000B Languages: Resource: All except: ERL JS PERL 6 POI 2006

3723. Snooker
Problem code: SNOOKER
Consider a rectangular snooker table with pockets only at the 4 corners of the

rectangle as shown in the image below. Consider all integer points on the boundary of the table. At each point, except the four corners (four pockets), you are allowed to hit the ball at an angle of 45 degrees from the side of the table from which you are hitting the ball. From any point on the boundary you can hit the ball in two directions and they are considered to be two different ways. For instance in the image shown below, from the point S the ball can be hit in two ways as shown. Given the dimensions of the board your task is to find the number of ways in which the ball can be hit so that iteventually reaches one of the four holes. Consider the ball to be of negligible size, like a point. Also assume that the ball does not lose energy due to collisions or friction - it keeps moving until it drops into a hole.

Input
The input has multiple test cases. Each test case consists of two space separated integers M and N, 2 M,N 10^5, representing the dimensions of the table. M=N=0 indicates the end of tests. There are atmost 300 testcases.

Output
For each test case output the number of ways as described, in a separate line.

Example
Input: 2 2 2 4 3 5

0 0 Output: 0 4 24

Added by: Date: Time limit:

Swarnaprakash 2009-01-16 3s

Source limit: 50000B Languages: Resource: All Kurukshetra 09 OPC

3725. Taming a T-REX


Problem code: TREX
Although evolution theory suggests that mammals started to dominate this world only after the mass extinction of the dinosaurs, there are some people who say man and dinosaurs may have co-existed for some time. Some argue that man even tamed and used some of these animals like the Flintstones. Shankar is such a believer and Sunil is a skeptic. One day Sunil asked Shankar, "If your argument is right how would you tame a TREX and what would you use it for?". Shankar replied, "We can use it for cow transportation from one village to another and we can keep it calm by feeding it at constant intervals". Sunil argued that the T-REX would have a maximum capacity C to carry. Let us say the distance is d km. If it is long, the T-REX would eat all the cows before it reaches the other village. Shankar argued that he knew a method that takes the maximum possible number of cows M to the destination. Sunil replied, "Oh really? I will give a few conditions. The T-REX will eat 1 cow every km until it reaches the destination. It may do so at any time during a 1 km stretch. So,there can not be a situation where the TREX has no cow to eat. If you drop cows in the middle, you can do so only at distances which are a multiple of 1 km. And, finally all the cows at the destination need to be alive i.e you can not cut a cow (fractions are not allowed)". Shankar was stunned. He needs your help. Given I (the number of cows at the starting village) , d and C findM, the maximum number of cows that can be taken to the destination subject to the mentioned constraints.

Input

There will be multiple test cases in the input. The input begins with a line containing a single integer n,n 300, which gives the number of test cases. Then n lines follow each containing the three integers I, 1 I 106, d, 1 d 105, and C, 1 I 106, in that order separated by spaces. d is in kilometers.

Output
For each test case print on a separate line the maximum number of cows that can be transported to the destination village under the given conditions.

Example
Input: 2 3000 1000 1000 30 10 10 Output: 533 5

Note:
A few test cases have been added and this problem has been rejudged on January 25th, 2009.

Added by: Date: Time limit:

Swarnaprakash 2009-01-17 5s

Source limit: 50000B Languages: Resource: All except: ERL JS PERL 6 Kurukshetra 09 OPC

2906. GCD2
Problem code: GCD2
Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two numbers. Then Felman implements it algorithm int gcd(int a, int b) {

if (b==0) return a; else return gcd(b,a%b); } and it proposes to Frank that makes it but with a little integer and another integer that has up to 250 digits. Your task is to help Frank programming an efficient code for the challenge of Felman.

Input
The first line of the input file contains a number representing the number of lines to follow. Each line consists of two number A and B (0 <= A <= 40000 and A <= B < 10^250).

Output
Print for each pair (A,B) in the input one integer representing the GCD of A and B.

Example
Input: 2 2 6 10 11 Output: 2 1

Added by: Date: Time limit: Source limit: Languages: Resource:

Frank Rafael Arteaga 2008-08-04 0.5s 1000B All except: C99 strict LISP sbcl LISP clisp ERL JAVA JS PERL PERL 6 PHP PYTH 2.5 RUBY My own Resource

902. Hangover
Problem code: HANGOVER
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.

Input
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.

Output
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples. Input: 1.00 3.71 0.04 5.19 0.00 Output: 3 card(s) 61 card(s) 1 card(s) 273 card(s)

Added by: Date: Time limit:

Wanderley Guimares 2006-06-09 1s

Source limit: 50000B Languages: Resource: All except: ERL JS PERL 6 ACM Mid Central Regionals 2001

3442. The last digit


Problem code: LASTDIG
Nestor was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His maths teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Nestor with his problem. You are given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000). You have to find the last digit of a^b.

Input
The first line of input contains an integer t, the number of test cases (t <= 30). t test cases follow. For each test case will appear a and b separated by space.

Output
For each test case output an integer per line representing the result.

Example
Input: 2 3 10 6 2 Output: 9 6

Added by: Date: Time limit:

Jose Daniel Rodrguez Morales 2008-12-01 1s

Source limit: 700B

Languages: Resource:

All except: ERL JS PERL 6 Own

LAST DIGIT OF A POWER


Determining the last digit of :

1. Last digit of

is the same as that of of

; ;

2. Determine the cyclicity number 3. Find the remainder 4. When digit of when

divided by the cyclisity; is the same as that of , where and when , then last

, then last digit of is the same as that of

is the cyclisity number.

Integer ending with 0, 1, 5 or 6, in the integer power k>0, has the same last digit as the base. Integers ending with 2, 3, 7 and 8 have a cyclicity of 4. Integers ending with 4 (eg. and when n is even ) have a cyclisity of 2. When n is odd will end with 4

will end with 6. ) have a cyclisity of 2. When n is odd will end with 9

Integers ending with 9 (eg. and when n is even

will end with 1.

Example: What is the last digit of Solution: Last digit of cyclisity of 1. 7^1=7 2. 7^2=9 3. 7^3=3 4. 7^4=1 (last (last (last (last : digit digit digit digit is is is is 7) 9) 3) 1)

? . Now we should determine the

is the same as that of

5. 7^5=7 (last digit is 7 again!) ... So, the cyclisity of 7 is 4.

Now divide 39 (power) by 4 (cyclisity), remainder is 3.So, the last digit of as that of the last digit of . , is the same as that of the last digit of

is the same , which is

5699. The last digit re-visited


Problem code: LASTDIG2
Pappu was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His maths teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Pappu with his problem. You are given two integer numbers: the base a (number of digits d, such that 1<=d<=1000) and the index b (0 <= b <= 922*10^15). You have to find the last digit of a^b. Input The first line of input contains an integer t, the number of test cases (t <= 30). t test cases follow. For each test case will appear a and b separated by space. Output For each test case output an integer per line representing the result. Example Input: 3 3 6 150 Output: 9 6 0

10 2 53

Added by: Date:

Hari
2009-12-27

Time limit:

1s

Source limit: 700B Languages: Resource: All except: PERL 6 harrydcoder

7380. Factorial challenge


Problem code: FUNFACT
Ling: Stir, let's go out and play our favorite game. Stir: I am already having fun with my first factorial program. Ling: Than I will give you a challenge on factorials. If you fail in it, you will have to come. Stir: ok.. Ling gives Stir a number x and the challenge is to find the largest value of n such that n! is not greater than the largest value that can be formed by x digits. Stir is stuck with the problem and needs your help. Now, it's your turn to make sure that Stir can continue having fun with factorials.

Input
The first line of the input contains a number t (about 10^5), the number of the test cases. The next t lines contain a number x (1 <= x <= 10^9).

Output
Output a total of t lines with each line containing the value n corresponding to the input case.

Example
Input: 2 1 7 Output: 3 10

Added by: Date: Time limit:

Siddharth Kothari 2010-09-23 15s

Source limit: 50000B Languages: Resource: All Own problem

6256. Inversion Count


Problem code: INVCNT Let A[0...n - 1] be an array of n distinct positive integers. If i < j and A[i] > A[j] then the pair (i, j) is called an inversion of A. Given n and an array A your task is to find the number of inversions of A. Input The first line contains t, the number of testcases followed by a blank space. Each of the t tests start with a number n (n <= 200000). Then n + 1 lines follow. In the ith line a number A[i - 1] is given (A[i - 1] <= 10^7). The (n + 1)th line is a blank space. Output For every test output one line giving the number of inversions of A. Example Input:

2 3 3 1 2 5 2 3

8 6 1
Output:

2 5
Added by: Date: Time limit: Paranoid Android 2010-03-06 5s

Source limit: 50000B Languages: All except: PERL 6

Você também pode gostar