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
Richard Deeming12-Nov-15 4:05
mveRichard Deeming12-Nov-15 4:05 
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 
You should consider this
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
	
	int i;
	int j;
	long long int pocet=0; // the numbers of combination
	long long int one_max;
	long long int two_max;
	long long int add=1; //for incrementing loops
	long long int reduc=1; // for decrementing loops

	if((one%2==0) && (two%2==0)){
		if(one>two){
			add=two/2;
			reduc=one/2;
		}
	}
	one_max=last/one;
	two_max=last/two;
	for(i=0;i<=one_max;i+=add){
		for(j=two_max;j>=0;j-=reduc){
			long long int tmp_one=(one*i);
			long long int tmp_two=(two*j);
			if(tmp_one+tmp_two==last){
				two_max=j;
				pocet++;
			}
		}
	}
	return pocet;
}

as the source code to provide. Because we can't use your source code as is. In the form of a function, we can do test without changing a single line in this code.

First remark: using int for i and j may be short and should be replaced with long long int to match other variables.
Patrice

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

GeneralRe: Fastest way to count nested loops Pin
Patrice T7-Nov-15 8:16
mvePatrice T7-Nov-15 8:16 
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 

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.