Problem 3 div2

Quick explanation:-This is very easy to solve just get all factors of m in sqrt m time and these all factors are your value of d now you got d you have a and m then you can calculate all valid n.

Problem 4 :-

(Just 10 lines of code)

ans=0;

n= length of string.

Traverse the string a from 0 to n-2 index (0 based index) if a[i]==a[i +1] then do ans +=((n*(n-1))/2 -n that is to include all ranges including both the characters

And if (a[i ] !=a[i +1] ) then simply do ans +=n; that is to include all substrings not including both of these two adjacent indices.

Happy coding.