Home » U++ Library support » U++ MT-multithreading and servers » GuiMT example does not calculate all divisors...
GuiMT example does not calculate all divisors... [message #11576] |
Tue, 18 September 2007 03:03 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
It goes only to sqrt(N) during testing for zero remainders (N mod A == 0).
That is enough to find all divisors, but you need to show not only A, but also B = N/A.
(it's not important in any way to the MT thing, but ... well ... I like when things are exact and accurate)
I would change this:
void WorkerThread(DivisorsInfo f)
{
String r1, r2;
int divisors = 0;
uint64 max = (uint64)sqrt((double)f.number) + 1;
for(uint64 i = 1; i < max; i++) {
if(f.gui->terminated)
break;
if(f.number % i == 0) {
r1 << ' ' << i;
divisors++;
uint64 j = f.number / i;
if ( j != i ) {
r2 = " " + AsString(j) + r2;
divisors++;
}
PostCallback(callback2(f.gui, &Divisors::ShowResult, f.line, "working..." + r1 + r2));
}
}
PostCallback(callback2(f.gui, &Divisors::ShowResult, f.line, AsString(divisors) + ": " + r1 + r2));
AtomicDec(f.gui->threads);
}
|
|
|
|
Goto Forum:
Current Time: Sat May 04 11:11:24 CEST 2024
Total time taken to generate the page: 0.02842 seconds
|