03-17-2014, 11:42 AM
To get the thread a bit back on track, I figured I'd post the solutions to a few of the ones I did. It turns out I stopped at 7, which is (surprise surprise) the one dealing with finding prime #10001. The language is C++, and I'd post the first one but it seems I never saved it. :/
Problem #2
Problem #3
Problem #4
Problem #5
Problem #2
Code:
int main(){
int a = 0, b = 2, c = 0;
while(a < 4000000){
c = c + a;
a = 4*a + b;
b = (a - b)/4;}
return c;}
Problem #3
Code:
int main(){int y=0, root=0, tot=0; double z, w, v;
vector <int> factor;
vector <int> prime; prime.push_back(1); cin >> w;
for(int x=2; x<sqrt(w); x++){z = x;
while((y != prime.size()) && (root < 2) && (prime.at(y) <= sqrt(z))){
if((x % prime.at(y)) == 0){root++;} y++;}
if(root == 1){prime.push_back(x);} y=0; root=0;}
for(int j=0; j<prime.size(); j++){
v = modf(w/prime.at(j), &z);
if(v == 0){factor.push_back(prime.at(j));}}
return factor.at(factor.size()-1);}
Problem #4
Code:
int main(){int a=999, b=990, d, palin=0; char c[7];
while((a >= b) && (b > 100)){d = a*b;
if(d > palin){sprintf_s(c, 7, "%d", d);
if((c[0] == c[5]) &&
(c[1] == c[4]) &&
(c[2] == c[3])){palin = d;}}
if(a == b){a = 999; b = b - 11;}
else{a--;}}
return palin;}
Problem #5
Code:
int main(){int q=0, root=0, y=0; double a=30, v=1, pr, ro, z;
vector <int> expo; expo.push_back(1);
vector <int> prime; prime.push_back(1);
for(int x=2; x<a; x++){z = x;
while((y != prime.size()) && (root < 2) && (prime.at(y) <= sqrt(z))){
if((x % prime.at(y)) == 0){root++;} y++;}
if(root == 1){prime.push_back(x);} y=0; root=0;}
for(int p=1; p<prime.size(); p++){
while(q <= ceil(sqrt(a))){
pr = prime.at(p); pr = pow(pr,q);
if(pr > a){expo.push_back(q-1); q=0; break;}
else{q++;}}}
for(int r=0; r<prime.size(); r++){
ro = prime.at(r);
v = v * pow(ro,expo.at(r));}
printf("%.20g\n", v); system("pause");
return 0;}