Problem:
Given the following function and it's results:
f(x,y) = x^y + y^x where x>0 and y>1
f(1,2) = 1^2 + 2^1 = 3
f(2,3) = 2^3 + 3^2 = 17
f(3,4) = 3^4 + 4^3 = 145
.
.
.
Using the above function denoted by f(x,y), and given that the initial values of x = 1 and y = 2, which increase by 1 each time, what are the last 4 digits of the sum of the first 15 function calls.
my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
main()
{
double x = 1;
double y = 2;
double f, fx = 0;
int counter;
cout << setprecision(0);
cout << fixed;
for (counter = 1; counter < 16; counter++)
{
f = pow(x ,y) + pow (y, x);
cout << "\n" << counter <<". f(" << x << ", " << y << ") = " << x << "^" << y << " + " << y << "^" << x <<" = " << f;
fx = fx + f;
x++;
y++;
}
cout <<" \n\n" << fx;
cout << "\n\n";
system("pause");
return 0;
}
|
output:
1. f(1, 2) = 1^2 + 2^1 = 3
2. f(2, 3) = 2^3 + 3^2 = 17
3. f(3, 4) = 3^4 + 4^3 = 145
4. f(4, 5) = 4^5 + 5^4 = 1649
5. f(5, 6) = 5^6 + 6^5 = 23401
6. f(6, 7) = 6^7 + 7^6 = 397585
7. f(7, 8) = 7^8 + 8^7 = 7861953
8. f(8, 9) = 8^9 + 9^8 = 177264449
9. f(9, 10) = 9^10 + 10^9 = 4486784401
10. f(10, 11) = 10^11 + 11^10 = 125937424601
11. f(11, 12) = 11^12 + 12^11 = 3881436747409
12. f(12, 13) = 12^13 + 13^12 = 130291290501553
13. f(13, 14) = 13^14 + 14^13 = 4731091158953433
14. f(14, 15) = 14^15 + 15^14 = 184761021583202850
15. f(15, 16) = 15^16 + 16^15 = 7721329860319737900
sum = 7910956276398901200
when i type 1200 as the last 4 digits of the sum of the first 15 first calls it says im wrong. :(
HELP!