Given the value of a+b and ab you will have to find the value of an+bn
?
Input
The input file contains several lines of inputs. Each line except the last line contains 3 non-negative integers p, q and n. Here p denotes the value of a+b andq denotes the value of ab. Input is terminated by a line containing only two zeroes. This line should not be processed. Each number in the input file fits in a signed 32-bit integer. There will be no such input so that you have to find the value of 00.
?
Output
For each line of input except the last one produce one line of output. This line contains the value of an+bn. You can always assume that an+bn fits in a signed 64-bit integer.
?
Sample Input Output for Sample Input
10 16 2
7 12 3
0 0 |
68 91 ? |
Problem setter: Shahriar Manzoor, Member of Elite Problemsetters' Panel
Special Thanks: Mohammad Sajjad Hossain
题意很明显就是求a^n+b^n;
我们发现f0=2,f1=a+b,f2=a^2+b^2=(a+b)*f1-a*b*f2....
依次递推,令p=a+b,q=a*b;
所以fi=fi-1*p-fi-2*q;
构造出矩阵后就可以求解了。
?
#include
#include
#include
#include
#include
#include
#include
#include
#include
HDU 4565
?
So Easy!
?
?
Problem Description A sequence S
n is defined as:
Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate S
n.
You, a top coder, say: So easy!
Input There are several test cases, each test case in one line contains four positive integers: a, b, n, m. Where 0< a, m < 2
15, (a-1)
2< b < a
2, 0 < b, n < 2
31.The input will finish with the end of file.
Output For each the case, output an integer S
n.
Sample Input
2 3 1 2013
2 3 2 2013
2 2 1 2013
Sample Output
4
14
4
题目要求这个式子答案,我们发现(a-1)^2
#include
#include
#include
#include
#include
#include
#include