jaskij 45 Junior Poster in Training

Mark me wrong, but a sieve for 8k numbers shouldn't run too long.

Why 8k? It's sqrt(64000000) and all divisors are mirrored after square root, ie:
Divisors of 28: 1,2,4,7,14,28. You can connect them in pairs: 1-28,2-14,4-7. And guess what? Left and right sides of the pair are parted by sqrt(28).
To make myself clear: if you want exactly 14 divisors (are they proper?) of a number, just check, if there are exactly seven divisors <sqrt(number).

At this point, all you need to do is make some optimalizations, like if a number is a square of an integer, there is a connection between it's and it's sqrt's divisors and so on.

jaskij 45 Junior Poster in Training

For 19.9, the current product element was 1+1.8e-10, don't really know what to think about this.

Seems it really was due to the Weierstrass product, and since the formula is the part of the assignment, I'm gonna leave it as is.

Thanks nezachem!

jaskij 45 Junior Poster in Training

Line 6 is a special constructor syntax, used if all you want to do in a constructor is assign values. Donno how to explain it much further without copying a longer text on constructors, classes and so on...

Second, for that code to work, you have to define the Point class somewhere.

Third, P is of type PointArray which has a member P, so to acces a single point inside your struct, you have to write P.P[pnt_index]

Fourth, not memset... why would you even want to use it there?
More like P.P.resize(size) to set the length of the array (if that's what you want to do)

And then to set the point coordinates use P.P[index].X=val; and P.P[index].Y=val;

jaskij 45 Junior Poster in Training

The program is supposed to compute the values of Euler's Gamma Function using an infinite product (formula #15 in the link), and it does so decently for low values, but the error gets too big for bigger values.
Using both Mathematica and Maxima for reference this is what I get for Gamma(19.9):
Gamma(19.9)~9.0406e16
Mathematica and Maxima difference: 9.6e2
Difference between my functions and Mathematica: 1.79e11
Difference between both of my functions: 1.21e5
What surprises me as well is similarity of results for both of my functions, because the second one gets to multiply values like 1e66 and 1e-61, while the first doesn't.
Compiled under Win7/Cygwin using g++ version 4.5.3 with -O2 flag.
Just now run it without -O2, will see if it makes a difference.

My question is: is this error due to my mistake, or is it due to inner workings of C++?
Code below.

long int const MAX_ITERS=1e8

long double eulerGamma(long double xVal){
	long double base=exp(-GAMMA*xVal)/xVal;
	long double product=1;
	for(int i=1;i<MAX_ITERS;i++){
		product*=exp(xVal/i)/(1+xVal/i);
	}
	return base*product;
}

long double eulerGamma2(long double xVal){
	long double base=exp(-GAMMA*xVal)/xVal;
	long double product=1;
	long double expon=0;
	for(int i=1;i<MAX_ITERS;i++){
		product*=(long double)i/((long double)i+xVal);
		expon+=(long double)1/(long double)i;
	}
	return base*exp(xVal*expon)*product;
}

Thanks in advance.

jaskij 45 Junior Poster in Training

Globals are EVIL. Period.
You have two ways:
1. declare the vector inside main() and pass a pointer (this is more C-way)

void foo(vector<vector<int> >* items){
};
void bar(vector<vector<int> >* items){
};
void foobar(vector<vector<int> >* items){
};

void main(){
	vector< vector<int> > items ( 6, vector<int> ( 6 ) );
	foo(&items);
	bar(&items;
	foobar(&items);
}

2. make a simple class (C++-way)

class foobar{
public:
	vector< vector<int> > items ( 6, vector<int> ( 6 ) );
	void foo(vector<vector<int> >* items){
	};
	void bar(vector<vector<int> >* items){
	};
	void foobar(vector<vector<int> >* items){
	};
};

void main(){
	foobar foo;
	foo.items[0][0]=5;
	foo.foo();
	foo.bar();
	foo.foobar();
}