Problem here Problem Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn’t enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can’t calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3. You’ve got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. Input The first line contains a non-empty string s — the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters “ + “. Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 char...
Problem here Problem Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7 . For example, numbers 47 , 744 , 4 are lucky and 5 , 17 , 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky. Input The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked. Output In the only line print “ YES " (without the quotes), if number n is almost lucky. Otherwise, print “ NO " (without the quotes). Sample test(s) input 47 output YES input 16 output YES input 78 output NO Note Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample...
Problem here Problem The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, …) are defined by the recurrence: eqnarray20 Write a program to calculate the Fibonacci Numbers. INPUT&OUTPUT The input to your program would be a sequence of numbers smaller or equal than 5000, each on a separate line, specifying which Fibonacci number to calculate. Your program should output the Fibonacci number for each input value, one per line. Sample input 5 7 11 output The Fibonacci number for 5 is 5 The Fibonacci number for 7 is 13 The Fibonacci number for 11 is 89 Solution 這題要用大數加法才不會WA #include <iostream> using namespace std ; int f[ 5001 ][ 5001 ] = { 0 }; int main(){ f[ 1 ][ 0 ] = 1 ; for ( int i = 2 ; i <= 5000 ; i++){ for ( int j = 0 ; j < 5001 ; j++){ f[i][j] += f[i- 1 ][j] + f[i- 2 ][j]; f[i][j+ 1 ] += f[i][j]/ 10 ; f[i][j] %= 10 ; } } int ...
Comments
Post a Comment