If you find all the small divisors of n that are less than sqrt(n), you can find the rest of them dividing n by the small ones.
By the way, this problem is widely known and googlable :) You can, for example, check out this link: http://stackoverflow.com/questions/26753839/efficiently-getting-all-divisors-of-a-given-number
Try coming up either with greedy algorithm or with two pointers algorithm.
Try to prove the following greedy: in each step we can choose the cheapest remaining mouse. If there is a computer left that has only one type of port suitable for this mouse, plug it there. Else if there is a computer with both types, plug it there. Else discard this mouse.
Try to also come up with the two pointers solution. If you cannot, it is described under the next spoiler.
Sort all of the USB mouses and all of the PS/2 mouses so that the price is non-descending. Then you will need to buy some prefix of USB mouses and some prefix of PS/2 mouses. Iterate over the number of USB mouses from 0 to their count. Now, the more USB mouses you buy and plug into computers, the less PS/2 mouses you will be able to buy, because the number of computers will only be decreasing. So you should move the first pointer forward, and in every iteration move the second pointer backwards until you reach such amount that it is possible to plug both USB and PC/2 mouses in.
Try thinking not about erasing a substring from B, but rather picking some number of characters (possibly zero) from the left, and some from the right.
Two pointers
For every prefix of B, count how big of a prefix of A you will require. Call these values p[i]. Put infinity in the cells where even whole A is not enough.
Same for every suffix of B count the length of the required suffix of A. Call these values s[i].
Now try increasing the length of prefix of B, while decreasing the length of the suffix until p[pref_len] + s[suf_len] is less or equal to the length of A.
The toughest thing about this task, is that you can go to the left. Try to come up with something to handle that.
Try to prove that in optimal solution you don't need to go more than one cell to the left before coming back.
Try to come up with a solution where you iterate over each frequency
Try to group stations that will be on the left side in a pair in one vector, and stations that will be on the right side in a pair into another.
Iterate over each frequncy. Suppose you are now on frequency i. Put all radio stations with frequencly i in the left vector, and all radio stations with frequencies i - k..i + k into the right vector. Notice, that the total size of all vectors you get this way is no more than (2 * k + 2) * n, because every radiostation will be one time in the left vector and at most 2 * k + 1 times in the right vector.
Now we need to calculate the number of possible pairs where left radio station is from vector left and right radio station is from vector right.
Sort stations in the left vector by position. Sort stations in the right vector by left bound of their range. Iterate over the stations from the left vector. Now, as you do that, larger and larger prefix of the right vector will have stations with their left bound less or equal to the coordinate of the currently processed station from the left vector. For each new such station you should add 1 to some RSQ structure (easiest is fenwick tree) to the position of this station. Since positions are up to 109, you will have to compress the coordinates (for example, use index of station in the sorted order instead of it's coordinate). Can you see how to query this fenwick tree to get the number of stations that match the currently processed station from the left vector?
F is coming up!