10036

Modular Problem: Mod of a negative number ..llike -16%3 = 2

It is DP problem.

such input of data is in p[]; divident is k;
let , s=a[0]%k;

and s=-a[0]%k;

if any of s <0

then s =s+k  [see mod of a negative number]

keep track in 2D array in a[0][s]=1.

s=s+p[1]%k,

for each s check this:

if any of s <0

then s =s+k  [see mod of a negative number]

 

a[1][s]=1 &

s=s-p[1]%k,

a[1][s]=1…and so on
until end of input array

and last if a[last][0] is 1 then divisible else not.

 

 

[highlight]Solultion:[/highlight]

 

Leave a Reply

Your email address will not be published. Required fields are marked *