First 50th prime numbers and depedency. Interesting 109 and 113.
bool __fastcall is_First(int x);
int *first_value;
int *step;
int *new_value;
int *how_many_first;
float *float_value;
float *float_value2;
float *sqrt_value;
float *sqrt_value2;
float *div_sqrt;
float *div_sqrt2;
float *end_sqrt;
bool __fastcall TForm1::is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
{
if(x%i==0)
++sum;
}
if(sum==2)
return true;
else
return false;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
init_Random();
first_value=new int[50];
step=new int[50];
new_value=new int[50];
how_many_first=new int[50];
float_value=new float[50];
float_value2=new float[50];
sqrt_value=new float[50];
sqrt_value2=new float[50];
div_sqrt=new float[50];
div_sqrt2=new float[50];
end_sqrt=new float[50];
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
delete first_value;
delete step;
delete new_value;
delete how_many_first;
delete float_value;
delete float_value2;
delete sqrt_value;
delete sqrt_value2;
delete div_sqrt;
delete div_sqrt2;
delete end_sqrt;
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int i,j,k;
i=0;
k=0;
j=2;
UnicodeString text[50];
do
{
if(is_First(j))
{
first_value[i]=j;
step[i]=k;
++i;
k=1;
}
else
++k;
++j;
}while(i<50);
for(i=0;i<50;i++)
{
ListBox1->Items->Add(IntToStr(i+1)+" - "+IntToStr(first_value[i]));
ListBox2->Items->Add(IntToStr(step[i]));
text[i]=IntToStr(first_value[i])+IntToStr(step[i]);
ListBox3->Items->Add(text[i]);
new_value[i]=StrToInt(text[i]);
}
i=0;
do
{
j=2;
k=0;
do
{
if(is_First(j))
++k;
++j;
}while(j<new_value[i]);
how_many_first[i]=k;
++i;
}while(i<50);
for(i=0;i<50;i++)
{
ListBox4->Items->Add(IntToStr(how_many_first[i]));
float_value[i]=(1.*new_value[i])/(1.*how_many_first[i]);
ListBox5->Items->Add(FloatToStr(float_value[i]));
float_value2[i]=(1.*float_value[i]*first_value[i]);
ListBox6->Items->Add(FloatToStr(float_value2[i]));
sqrt_value[i]=sqrt(float_value2[i]);
sqrt_value2[i]=sqrt(1.*first_value[i]);
div_sqrt[i]=sqrt_value[i]/sqrt_value2[i];
ListBox7->Items->Add(FloatToStr(sqrt_value[i]));
ListBox8->Items->Add(FloatToStr(sqrt_value2[i]));
ListBox9->Items->Add(FloatToStr(div_sqrt[i]));
div_sqrt2[i]=sqrt(1.*(step[i]+first_value[i]));
ListBox10->Items->Add(FloatToStr(div_sqrt2[i]));
end_sqrt[i]=div_sqrt2[i]/sqrt_value2[i];
ListBox11->Items->Add(FloatToStr(end_sqrt[i]));
}
}