Click here to Skip to main content
15,887,302 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Algorithm needed to find a point on A4 size plane Pin
Chris Maunder12-Nov-15 4:15
cofounderChris Maunder12-Nov-15 4:15 
QuestionFastest way to count nested loops Pin
Member 113783027-Nov-15 2:32
Member 113783027-Nov-15 2:32 
AnswerRe: Fastest way to count nested loops Pin
Patrice T7-Nov-15 4:57
mvePatrice T7-Nov-15 4:57 
GeneralRe: Fastest way to count nested loops Pin
Member 113783027-Nov-15 5:02
Member 113783027-Nov-15 5:02 
GeneralRe: Fastest way to count nested loops Pin
PIEBALDconsult7-Nov-15 5:18
mvePIEBALDconsult7-Nov-15 5:18 
GeneralRe: Fastest way to count nested loops Pin
Member 113783027-Nov-15 5:36
Member 113783027-Nov-15 5:36 
GeneralRe: Fastest way to count nested loops Pin
Patrice T7-Nov-15 7:51
mvePatrice T7-Nov-15 7:51 
GeneralRe: Fastest way to count nested loops Pin
Patrice T7-Nov-15 8:16
mvePatrice T7-Nov-15 8:16 
Here is code with first batch of changes. the code is changed to a function for practical reasons.
C++
long long int MyFunc (long long int one, long long int two, long long int last) {
	// one; // first number inputed by user
	// two; // second number inputed by user
	// int last; // final number inputed by user - wanted result
	
	// Question: How many (i,j) pairs (as positive integers) will verify
	// one*i+ two*j = last (constant part is on right)
	
	long long int i;
	long long int j;
	long long int pocet=0; // the numbers of combination
	
	for(i=0;i*one <=last;i++){
		// two*j = last - one*i (constant part is on right)
		// j = (last - one*i) / two (constant part is on right)
		if ((last - one*i )% two == 0) { // integer ?
			// solution
			j= (last - one*i) / two;
			pocet++;
		}
	}
	return pocet;
}

I just stick to the problem here.
I just take advantage of mathematics to change the equation as i is known. This should already improve the runtime.
Patrice

“Everything should be made as simple as possible, but no simpler.” Albert Einstein

GeneralRe: Fastest way to count nested loops Pin
Member 113783027-Nov-15 8:27
Member 113783027-Nov-15 8:27 
GeneralRe: Fastest way to count nested loops Pin
Patrice T7-Nov-15 8:52
mvePatrice T7-Nov-15 8:52 
GeneralRe: Fastest way to count nested loops Pin
Member 113783027-Nov-15 9:08
Member 113783027-Nov-15 9:08 
GeneralRe: Fastest way to count nested loops Pin
Patrice T7-Nov-15 9:19
mvePatrice T7-Nov-15 9:19 
GeneralRe: Fastest way to count nested loops Pin
harold aptroot7-Nov-15 5:20
harold aptroot7-Nov-15 5:20 
AnswerRe: Fastest way to count nested loops Pin
Luc Pattyn3-Jan-16 6:37
sitebuilderLuc Pattyn3-Jan-16 6:37 
Questionhow do you calculate a primitive operation in algorithm analysis Pin
Member 118975665-Nov-15 21:15
Member 118975665-Nov-15 21:15 
AnswerRe: how do you calculate a primitive operation in algorithm analysis Pin
Richard Deeming6-Nov-15 2:02
mveRichard Deeming6-Nov-15 2:02 
GeneralRe: how do you calculate a primitive operation in algorithm analysis Pin
Member 118975666-Nov-15 2:57
Member 118975666-Nov-15 2:57 
GeneralRe: how do you calculate a primitive operation in algorithm analysis Pin
Richard Deeming6-Nov-15 3:03
mveRichard Deeming6-Nov-15 3:03 
GeneralRe: how do you calculate a primitive operation in algorithm analysis Pin
jschell7-Nov-15 6:18
jschell7-Nov-15 6:18 
QuestionBinary Polynomial Multiplication Pin
Member 120276965-Nov-15 2:04
Member 120276965-Nov-15 2:04 
GeneralRe: Binary Polynomial Multiplication Pin
harold aptroot5-Nov-15 3:40
harold aptroot5-Nov-15 3:40 
GeneralRe: Binary Polynomial Multiplication Pin
Member 120276965-Nov-15 20:19
Member 120276965-Nov-15 20:19 
GeneralRe: Binary Polynomial Multiplication Pin
Patrice T5-Nov-15 17:24
mvePatrice T5-Nov-15 17:24 
Questionneed help with number base conversion algorithm for computers Pin
mickcs4-Nov-15 10:14
mickcs4-Nov-15 10:14 
AnswerRe: need help with number base conversion algorithm for computers Pin
Richard Andrew x644-Nov-15 10:36
professionalRichard Andrew x644-Nov-15 10:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.