| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12439 | Little Brick's Functions |
|
| 12452 | Binary Lottery |
|
Description
One day, Little-Brick(小磚頭) found 3 functions,
GCD, LCM and POWER
GCD(a, b) is to compute the greatest common divisor of a and b,
LCM(a, b) is to compute the least common multiplier of a and b,
POWER(a, b) is to compute ab.
Little-Brick's is not so good as math,
even that he doesn't know how to use these functions,
he doesn't care about it,
he decide to take 4 numbers and substitute them into these functions.
Now, he is asking you to tell him the answer of the result of substitute these 4 numbers into functions in all order,
that is, given you 4 integer A, B, C, D,
you should output the result of GCD(LCM(POWER(A, B), C), D), GCD(POWER(LCM(A, B), C), D), LCM(GCD(POWER(A, B), C), D), LCM(POWER(GCD(A, B), C), D), POWER(GCD(LCM(A, B), C), D), POWER(LCM(GCD(A, B), C), D), each in a single line.
Hint: LCM(a, b) = a * b / GCD(a, b)
You can follow the format of the following suggested code,
or feel free to have your own version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <stdio.h> int gcd(int a, int b) { // your code here } int lcm(int a, int b) { // your code here } int power(int a, int b) { // your code here } int main() { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); printf("%d\n", gcd(lcm(power(a, b), c), d)); // ... other 5 lines return 0; } |
ouo.
Note:
Please solve the problem using recursion rather than loop. Practice recursion :)
Input
Input contain 4 integer A, B, C, D, seperate by spaces.
1<= A, B, C, D <= 100
Output
Output contains 6 lines.
Output he result of GCD(LCM(POWER(A, B), C), D), GCD(POWER(LCM(A, B), C), D), LCM(GCD(POWER(A, B), C), D), LCM(POWER(GCD(A, B), C), D), POWER(GCD(LCM(A, B), C), D), POWER(LCM(GCD(A, B), C), D), each in a single line.
It is guarantee that the result of every call of function will < 231
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The rule of Binary Lottery is listed as follows:
You can choose m (0 <= m <= 20) distinct numbers to buy ranging from 0 ~ 19, and buying m numbers costs m^2 dollars. Let buying set be the numbers you buy.
The are two kinds of prizes in Binary Lottery : ordinary prize and special prize. Each time the lottery draws, there will be two sets of numbers : ordinary set and special set. Each set contains distinct numbers ranging from 0 ~ 19.
Buying set, ordinary set, and special set are expressed as a 32-bit integer, respectively. Let's say buying set contains a0, a1, ..., am and the integer representing it is A. Then the a0-th, a1-th, ..., am-th bit counted from the rightmost in A are 1 and the rest bits in A are 0. For example if buying set = {1, 2, 7}, then it will be expressed as 134, since 134 = (10000110)_2. Same way is used to represent ordinary set and special set.
For ordinary prize, let k be the number of numbers buying set and ordinary set have in common. The prize you win is k^3 dollars.
For special prize, if the buying set is exactly the same as the special set, then you win sp dollars.
Given the daily result of the Binary Lottery and the numbers you buy, please calculate the money you make every day. The money you make = (the sum of prize you win) - (the money you spend to buy m numbers).
Suggest way of implementing
It is encouraged to split you program in to functions (instead of stuffing everything in main function). The following is just for reference.
Use the link to download code, or you will get some error if you just copy the code below.
(http://140.114.86.238/problem/partial/12442.c/ to download code)
#include <stdio.h> /* TODO: * count number of '1' bit in an integer * @param x : integer to be counted * @return number of '1' in x */ int getOneNum(int x) { } /* TODO: * cost to buy numbers in B * @param B : bit vector of bought numbers * @return (number of ones in B)^2 */ int cost(int B) { } /* TODO: * calulate money win from ordinary prize * @param B : bit vector of bought numbers * @param O : bit vector of ordinary set * @return money win from ordinary prize */ int ordinary(int B, int O) { } /* TODO: * calulate money win from special prize * @param B : bit vector of bought numbers * @param S : bit vector of special set * @param sp : money for special prize * @return money win from special prize */ int special(int B, int S, int sp) { } int main() { int D, B, O, S, sp; scanf("%d", &D); while(D--) { scanf("%d %d %d %d",&B, &O, &S, &sp); // TODO // calculate money win in a day and output } return 0; }
Input
The input is as the following form :
D B_1 O_1 S_1 sp_1 B_2 O_2 S_2 sp_2 ... B_D O_D S_D sp_D
The first line D is an integer, meaning that you are given D days of data.
There are 4 integers on each line, being the data on each day. For i-th line, B_i is the integer representing the numbers you buy, O_i is the ordinary set, S_i is the special set, sp_i is the special prize on that day.
-
1 <= D <= 1000
-
0 <= B_i, O_i, S_i < 2^20
-
0 <= sp_i <= 2000
Output
For each day, output the money you make. Remember to add a new line character in each line.