• Loading...

Problem 7: Equation in Combinations

Points:

Small Case: 5 Answer: 76919904

Large Case: 10 Answer: 99989016

Given an equation

2*(aCb)=(a+2)Cb

where

(aCb)=a!/(b!*(a-b)!)

There are various values of (a,b) as (a[i],b[i]) which satisfy it with a[i]+b[i]>a[i-1]+b[i-1]

For e.g first such pair is (2,1)

Given n,find sum of nth such pair modulo 100000007 i.e (a[n]+b[n]) mod 100000007.

Small Case: n=100
Large Case: n=100000000

Solution:

The recurrence relation of a and b are:

a[n]=6*a[n-1]-a[n-2]+6

b[n]=6*b[n-1]-b[n-2]

Code:


#include<iostream>
#define MOD 100000007
using namespace std;

int main(){
	long long int n;
	long long int a,b,a1,b1,a2,b2;
	n=100;
	a2=2;
	a1=19;
	b2=1;
	b1=6;
	for(int i=2;i<n;i++){
		a=((6*a1)%MOD-a2+MOD+6)%MOD;
		b=((6*b1)%MOD-b2+MOD)%MOD;
		a2=a1;		
		a1=a;
		b2=b1;
		b1=b;
	}
	cout<<(a+b)%MOD<<endl;
	return 0;	
}

Submit your solution

You need to be logged in to submit a solution.

discussions


gmunkhbaatarmnfirst of a, b
Q:> For e.g first such pair is (2,1)is equavalent to:a[1] = 2;b[1] = 1;?
A:yes

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 %)