Im does (for myself) a very difficult task, where I have to calculate the maximum possible number of sequences when setting the number n of segments.
I found out that the Catalan number represents these sequences, and I got it to work with n <= 32. The results that I get should be calculated modulo 1.000.000.007. The problem is that βqβ and βpβ become large for a long int and I cannot just mod 1.000.000.007 before dividing βqβ and βpβ, because I get a different result.
My question is, is there really an effective way to solve my problem, or do I need to think about storing values ββdifferently? My limitations are as follows: - only stdio.h / iostream - only integers - n <= 20,000,000 - n> = 2
#include <stdio.h> long long cat(long long l, long long m, long long n); int main(){ long long n = 0; long long val; scanf("%lld", &n); val = cat(1, 1, n / 2); printf("%lld", (val)); return 0; } long long cat(long long q, long long p, long long n){ if (n == 0) { return (q / p) % 1000000007; } else { q *= 4 * n - 2; } p *= (n + 1); return cat(q, p, n - 1); }
performance c division modulo store
jHN
source share