• Loading...

Power of 2(Problem 2)

Points : 20

Answer : 102826018491314080

Given the equation 2n=7A2+B2, we have to find odd A and B for each n>2.

For example,
If n=3 then A=1 and B=1.
If n=10 then A=3 and B=31.

The sum of all such As and Bs for n below 22 is 4344.

Find the sum of all such As and Bs for n<111.

Solution

By looking at the above table we can derive the transformation that

If (An-1 + Bn-1)/2 is even
An = (|An-1 - Bn-1|)/2
Bn = (7An-1 +Bn-1)/2
Else if (An-1 + Bn-1)/2 is odd
An = (An-1 + Bn-1)/2
Bn = (|7An-1 - Bn-1|)/2

Here is the judge solution :

Code

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     long long x1=1,y1=1,x2,y2,sumx=1,sumy=1,x;
  6.     for (int n=4;n<111;n++)
  7.     {
  8.         x = (x1+y1)/2;
  9.         if (x%2==0)
  10.         {
  11.                    x2=(x1-y1)/2.0;
  12.                    y2=(7*x1+y1)/2.0;
  13.         }
  14.         else
  15.         {
  16.             x2=(x1+y1)/2.0;
  17.             y2=(7*x1-y1)/2.0;
  18.         }
  19.         sumx+=x2;
  20.         sumy+=y2;
  21.         x1=x2;
  22.         y1=y2;
  23.     }
  24.     cout<<sumx+sumy<<endl;
  25. }
#include<iostream>
using namespace std;
int main()
{
    long long x1=1,y1=1,x2,y2,sumx=1,sumy=1,x;
    for (int n=4;n<111;n++)
    {
        x = (x1+y1)/2;
        if (x%2==0)
        {
                   x2=(x1-y1)/2.0;
                   y2=(7*x1+y1)/2.0;
        }
        else
        {
            x2=(x1+y1)/2.0;
            y2=(7*x1-y1)/2.0;
        }
        sumx+=x2;
        sumy+=y2;
        x1=x2;
        y1=y2;
    }
    cout<<sumx+sumy<<endl;
}

Submit your solution

You need to be logged in to submit a solution.

discussions


Strikersoftware
Q:in which software this code works ?n
A:Its a CPP code. Use GNU CPP Compiler.
Kronosmultiple sums
Q:if a value of n has multiple values of A and B that work, we count them too right?
A:Multiple values are not possible.
elixir786multiple answers
Q:for n =10, is the pair A = 8 and B=24 possible?
A:No. Both A and B has to be odd as mentioned in the problem statement.
A_A_Lunyovanswer to large
Q:May be we need find remainder of this sum some modulo?nBecause obviously A and B is about 2^(n/2)nwhich is really large numbers.
A:Thanks for the catch. The statement will be rectified soon.

post a question

Loading...

Top Scorers
KoenR 195
DrKorbin 185
Silence 150
A_A_Lunyov 145
cedricl 145
kozima 145
cgy4ever 135
ProjectYoung 130
pankdm 130
dzetkulic 130
Submissions
Problem1
15 pt
You are not logged in
79
submissions

23
correct (29 %)


Problem2
20 pt
You are not logged in
35
submissions

18
correct (51 %)


Problem3
25 pt
You are not logged in
29
submissions

6
correct (20 %)


Problem4
15 pt
You are not logged in
80
submissions

54
correct (67 %)


Problem5
25 pt
You are not logged in
35
submissions

13
correct (37 %)


Problem6
25 pt
You are not logged in
39
submissions

17
correct (43 %)


Problem7
25 pt
You are not logged in
26
submissions

13
correct (50 %)


Problem8
10 pt
You are not logged in
60
submissions

39
correct (65 %)


Problem9
20 pt
You are not logged in
32
submissions

25
correct (78 %)


Problem10
15 pt
You are not logged in
57
submissions

34
correct (59 %)