• Loading...

Problem 2: Two units triangle

Points:

Small Case: 5 Answer: 28657704

Large Case: 10 Answer: 99997667

Given a triangle with a side of length 't' units and another side of length 't+1' units, it is specified that the altitude of the triangle on side of length 't' units is at distance of 2 units from centre of that side and the area of triangle is integer.
For e.g

Right Angled triangle

Above figure shows first such triangle. It is a right angled triangle with side lengths 3 units,4 units and 5 units ,altitude 3 units and the area 6 units.

The sides of triangle are integers.

Find the altitude modulo 100000007 of Nth such triangle.

Small Case: N=15
Large Case: N=100000000

Solution:

From the constraints given in the problem, it can be proved that the 3rd side of the traingle has length 't-1', and the area of the traingle will be integral. Such traingles are called as 'Brahmagupta Traingle' and the altitute of such triangles follow the following recurrence relation : f(n)=4*f(n-1)-f(n-2), f(1)=3, f(2)=12 .

Reference:Raymond A. Beauregard and E. R. Suryanarayan, The Brahmagupta Triangles[1998].

Code:


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<cmath>
#define ll long long int
#define MAX 100000000ll
#define MOD 100000007ll
using namespace std;
ll pr[MAX]={0};
int main()
{
    ll i;
    pr[1]=1;
    pr[2]=4;
    for(i=3;i<=MAX;i++)
        pr[i]=((pr[i-1]<<2)%MOD-pr[i-2]%MOD+MOD)%MOD;
    printf("%lld\n",(3*pr[MAX])%MOD);
    return 0;
}

Submit your solution

You need to be logged in to submit a solution.

discussions


MarioYCvalue of t
Q:Isn\\\'t t always equal to 4? since the statement says \\\" it is specified that the altitude of the triangle on side of length \\\'t\\\' units is at distance of 2 units from centre of that side\\\"
A:no
cedricl2Is the following valid?
Q:Is a right triangle with side lengths 4, 5, and sqrt(41) valid?
A:no
saurabh8bquery
Q:n starts from 0 or 1 ?
A:n starts from 1.\r\n
InkyAltitude
Q:Should the altitude be integer?
A:yes
saurabhkr_1989second triangle
Q:what will be the second such triangle.. does all the triangles will be right angled triangles
A:There are sufficient details in the question to figure out all the triangles.
bbbasicSide lengths
Q:Are the side lengths also integers?
A:yes
saurabhcatchwhat is N
Q:what is N
A:There are many such triangles possible. You have to sort them on the basis of t and report the required answer for Nth triangle.

post a question

Loading...

Problem 1
Problem 2
Problem 3
Problem 4
Problem 5 (bonus) Expired
Problem 1
Problem 2
Problem 3
Problem 4 (bonus) Expired
Top Scorers
rng_58 235
Anton_Lunyov 225
tourist 190
Silence 180
cedricl2 175
cgy4ever 175
DrKorbin 165
Koen 155
bbbasic 150
lunae_2 150
Submissions
Problem 1
10 pt
not submitted
98
submissions

19
correct (19 %)



25 pt
not submitted
2
submissions

1
correct (50 %)


Problem 2
5 pt
not submitted
95
submissions

38
correct (40 %)



10 pt
not submitted
19
submissions

15
correct (78 %)


Problem 3
5 pt
not submitted
153
submissions

117
correct (76 %)



15 pt
not submitted
44
submissions

25
correct (56 %)


Problem 4
10 pt
not submitted
152
submissions

54
correct (35 %)



15 pt
not submitted
23
submissions

10
correct (43 %)


Problem 5
10 pt
not submitted
36
submissions

28
correct (77 %)



20 pt
not submitted
6
submissions

2
correct (33 %)


Problem 6
5 pt
not submitted
41
submissions

29
correct (70 %)



10 pt
not submitted
15
submissions

14
correct (93 %)


Problem 7
5 pt
not submitted
38
submissions

17
correct (44 %)



10 pt
not submitted
16
submissions

15
correct (93 %)


Problem 8
5 pt
not submitted
127
submissions

104
correct (81 %)



15 pt
not submitted
47
submissions

34
correct (72 %)


Problem 9
5 pt
not submitted
86
submissions

35
correct (40 %)



15 pt
not submitted
16
submissions

15
correct (93 %)


Problem 10
5 pt
not submitted
45
submissions

23
correct (51 %)



15 pt
not submitted
15
submissions

14
correct (93 %)


Problem 11
5 pt
not submitted
81
submissions

27
correct (33 %)



15 pt
not submitted
8
submissions

3
correct (37 %)


Problem 12
5 pt
not submitted
104
submissions

88
correct (84 %)



10 pt
not submitted
31
submissions

21
correct (67 %)