Easy
You are standing at a magical well. It has two positive integers written on it: a and b. Each time you cast a magic marble into the well, it gives you a * b dollars and then both a and b increase by 1. You have n magic marbles. How much money will you make?
Example
For a = 1, b = 2, and n = 2, the output should be
magicalWell(a, b, n) = 8.
You will cast your first marble and get $2, after which the numbers will become 2 and 3. When you cast your second marble, the well will give you $6. Overall, you'll make $8. So, the output is 8.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] integer a
Guaranteed constraints:
1 ≤ a ≤ 2000. -
[input] integer b
Guaranteed constraints:
1 ≤ b ≤ 2000. -
[input] integer n
The number of magic marbles in your possession, a non-negative integer.
Guaranteed constraints:
0 ≤ n ≤ 5. -
[output] integer
[C] Syntax Tips
// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
char * answer = malloc(strlen(name) + 8);
printf("This prints to the console when you Run Tests");
strcpy(answer, "Hello, ");
strcat(answer, name);
return answer;
}
Solution
int magicalWell(int a,int b,int n)
{
int money=0;
for(int i=0;i<n;i++,a++,b++)
money+=a*b;
return money;
}
'Codesignal' 카테고리의 다른 글
<Codesignal> Addition Without Carrying (0) | 2020.04.12 |
---|---|
<Codesignal> Lineup (0) | 2020.04.12 |
<Codesignal> Count Sum of Two Representations 2 (0) | 2020.04.12 |
<Codesignal> Least Factorial (0) | 2020.04.12 |
<Codesignal> Second-Rightmost Zero Bit (0) | 2020.04.12 |