# Spoj ACPC10A solution. Spoj Whats Next solution.

This question is based on direct application of Arithmetic Progression‘s common difference and Geometric Progression‘ common ratio.

First check whether there is a common difference (c-b) and (b-a) , or whether there is common ratio (c/b) and (b/a).

### Spoj ACPC10A solution code:

```#include <bits/stdc++.h>
using namespace std;

int main() {
std::ios::sync_with_stdio(false);

int a,b,c;
cin>>a>>b>>c;

//will stop if all 3 are zeros
while(a!=0 || b!=0 || c!=0)
{
//if the series is AP
if((c-b) == (b-a))
{
// c-b = common difference
cout<<"AP "<<c+(c-b)<<"\n";
}
//else it is GP
else
{
// c/b = common ratio
cout<<"GP "<<c*(c/b)<<"\n";
}
cin>>a>>b>>c;
}
return 0;
}```

# Spoj PRISMSA solution. Spoj TRIANGULAR PRISM solution.

This question is of minimization of Surface Area for a Triangular Prism whose volume is given.
Applying the standard differentiating procedure, the value of “a” comes out to be:

a = (4V)1/3  , h = a/ sqrt(3)

Putting the values together, we get:

Surface Area = 3*a*a*sqrt(3) / 2;

Using this, the minimum surface area can be calculated.

### Spoj PRISMSA solution code:

```#include<bits/stdc++.h>
using namespace std;

int main()
{
std::ios::sync_with_stdio(false);
int t;
double vol,surface_area,a;
cin>>t;
while(t--)
{
cin>>vol;

/*the value of a calculated for minimum
Surface Area*/
a = pow(4*vol,0.3333333333333333333333333);
surface_area = 3*a*a*sqrt(3)/2;

cout << std::fixed << std::setprecision(10) << surface_area<<"\n";
}
return 0;
}```

# Spoj TETRA solution. Spoj Sphere in a tetrahedron  solution.

This question is based on geometry as we need to find the radius of the sphere subscribed inside an irregular tetrahedron

Required Radius = (3*volume of Tetrahedron)/(sum of surface areas of triangular faces).

This requires calculation of volume of Irregular Tetrahedron using its edge lengths.
This question can be seen as the extension of Spoj Pyramids Problem, in which volume of tetrahedron is calculated.

### Spoj TETRA solution code:

```#include <bits/stdc++.h>
using namespace std;

/*Heron's Formula to find area of a triangluar face*/
double areaHeron(double a1,double a2,double a3)
{
double s=(a1+a2+a3)/2.0;
return sqrt(s*(s-a1)*(s-a2)*(s-a3));
}

int main() {
std::ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
double u,v,w,U,V,W,vol,a,b=12,total_area=0;
cin>>u>>v>>w>>W>>V>>U;

/*Adding total area of all sides*/
total_area += areaHeron(u,V,w);
total_area += areaHeron(W,u,v);
total_area += areaHeron(W,V,U);
total_area += areaHeron(U,v,w);

/*steps to calculate volume of a
Tetrahedron using formula*/
a=4*(pow(u,2)*pow(v,2)*pow(w,2))
- pow(u,2)*pow((pow(v,2)+pow(w,2)-pow(U,2)),2)
- pow(v,2)*pow((pow(w,2)+pow(u,2)-pow(V,2)),2)
- pow(w,2)*pow((pow(u,2)+pow(v,2)-pow(W,2)),2)
+ (
pow(v,2)+pow(w,2)-pow(U,2))*
(pow(w,2)+pow(u,2)-pow(V,2))*
(pow(u,2)+pow(v,2)-pow(W,2)
);
vol = sqrt(a);
vol /= b;

/*the radius of the inscribed circle
is (3*volume)/total_area */
cout << std::fixed << std::setprecision(4) << vol*3/total_area<<"\n";
}
return 0;
}```

# Spoj PIR solution. Spoj Pyramids solution.

This question is based on geometry as we need to find the volume of Irregular Tetrahedron using its edge lengths.
Here is the formula required:

### Spoj Pyramids solution code:

```#include <bits/stdc++.h>
using namespace std;

int main() {
std::ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
double u,v,w,U,V,W,vol,a,b=12;
cin>>u>>v>>w>>W>>V>>U;

/*steps to calculate volume of a
Tetrahedron using formula*/
a=4*(pow(u,2)*pow(v,2)*pow(w,2))
- pow(u,2)*pow((pow(v,2)+pow(w,2)-pow(U,2)),2)
- pow(v,2)*pow((pow(w,2)+pow(u,2)-pow(V,2)),2)
- pow(w,2)*pow((pow(u,2)+pow(v,2)-pow(W,2)),2)
+ (
pow(v,2)+pow(w,2)-pow(U,2))*
(pow(w,2)+pow(u,2)-pow(V,2))*
(pow(u,2)+pow(v,2)-pow(W,2)
);
vol = sqrt(a);
vol /= b;

cout << std::fixed << std::setprecision(4) << vol<<"\n";
}
return 0;
}```