[Solved] Finding solutions for a given pair (number of factors, number of prime factors)

Let p1, p2, p3, … pk be the prime factors of some positive integer n. By the fundamental theorem of arithmetic, n can be represented as p1e1•p2e2•p3e3• … pkek for some positive integers e1, e2, e3, … ek. Furthermore, any such set of such positive integers represents one positive integer in this way. Every factor … Read more

[Solved] How to add a value in a matrix and make it decrease in radial way? [closed]

[EDIT] So based on you’re edit i thought this solution. Since you don’t specify any programming language i’ll use some c-like functional programming. I’ll leave you the work of transforming it to object oriented if you need it. Input: Global maxtrix that starts in M[0,0] and ends in M[100’000, 100’000] (Note that, to make it … Read more

[Solved] Filter element in array of doubles

The for-loop solution should be the easiest, as you can use the Math.floor function to get the start of your desired list: for (double d = Math.floor(start); d <= Math.ceil(end); d += 1.0) list.add(d); 13 solved Filter element in array of doubles

[Solved] Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character

The first mistake is pushing all the characters on the stack outside of the if statement. Also you should check if stack is empty before removing items from it. Otherwise EmptyStackException is thrown. // stack1.push(S.charAt(i)); <– remove this line if (S.charAt(i)!=’#’) { stack1.push(S.charAt(i)); }else if (!stack1.isEmpty()) { // <– add this check stack1.pop(); } The … Read more

[Solved] logic help for smallest/largest value

You need to choose a standard unit of measure. The question suggests meters, so use that (you can use float or double for this, depending on what precision you need). The problem is then simple, create some variables for the sum, smallest seen, and largest seen, the for each new input, convert to the standard … Read more

[Solved] How can I still optimize the code?

You can slightly improve your code by removing queue, you don’t need this. The rest of the code looks algorithmically optimal. #include <map> #include <iostream> using namespace std; int main() { int a,b; map<int, int> AB; map<int, int>::iterator it; std::ios::sync_with_stdio(false); while (1) { cin >> a; if (a == -1)break; cin >> b; AB.insert(pair<int, int>(a, … Read more

[Solved] Algorithms for bucket sort

This is basically a link only answer but it gives you the information you need to formulate a good question. Bucket Sort Wikipedia’s step 1, where you “Set up an array of initially empty buckets”, will need to include buckets for negative numbers. Counting Sort “Compared to counting sort, bucket sort requires linked lists, dynamic … Read more

[Solved] Student-Project allocation algorithms? [closed]

Since you didn’t really give more details, we can only give you broad pointers. First Check out: Stable Marriage Problem. And also search the web for Bipartite matching (or in cases of weighted edges: Assignment Problem, which can be solved using: Hungaring Algorithm). Note that a solution to the stable marriage problem might also solve … Read more