# P-sequences

# P-sequences

+ 0 comments Here is my solution in java, javascript, python, C, C++, Csharp HackerRank P-sequences Problem Solution

+ 0 comments This problem is definitely easier than a fair number of the medium-rated DP problems. At least in this case it's obvious how to relate the desired solution to the solution to a smaller version of the problem. Sure, you need to figure out how to condense some of the sub-problems together so you can handle large P without running out of time or memory, but that's a much more straightforward problem.

+ 0 comments **Here is P-sequences problem solution**- https://programs.programmingoneonone.com/2021/07/hackerrank-p-sequences-problem-solution.html

+ 0 comments The algorithm is correct

Still it will not work for very large number TestCases: 10,11,13,16,17 and 18. They exceed computational capacity of 53bit integers. Then, a special multiplication procedure will be needed in order to get the correct modulus without errors induced by those really really really really big numbers,,,,,

function pSequences(n, p) { // Write your code here const MOD = 1000000000+7 let root = parseInt(Math.sqrt(p)), last = root*2-((root*(root+1)>p)?2:1), qtty = [], val=[], calc=[], i=0, j=last, accum=0, size=last+1 while (accum < p) calc[j--] = (accum += (val[i] = (qtty[i++] = (parseInt(p/parseInt(p/(accum+1))) - accum)))) while(n-->=2) { let next = new Array(size) accum = 0 for(i=0,j=last;i<=last;i++,j--) next[j] = (accum = (accum + (val[i] = ((qtty[i] * calc[i])%MOD)))%MOD) calc = next } return accum % MOD }

+ 0 comments In JavaScript,

var result=0; for(var i=1;i<=n;i++) { for(var j=1;j<=n;j++) { if(i*j<=p) { result = result+1; } } } return(result)

something is not working here.

Sort 14 Discussions, By:

Please Login in order to post a comment