tip
leap year
bool leapYear(int year)
{
(year%4==0&&year%100!=0)||(year%400==0)?return true:return false;
}
isprime
bool isprime(int x)//大于2开始
{
bool t=true;
for(int i=2;i<=x/2;i++)
{
if(x%i==0){t=false;break;}
}
return t;
}
求立方根
float cuberoot(float x)
{
float croot,root;
const float eps=1e-6;
croot=x;
do{root=croot;
croot=(2*root+x/(root*root))/3;}
while(fabs(croot-root)>eps);
return croot;
}
最大公约数
int HCF(int x,int y){
int min=(x<=y?x:y);
int i=min;
for(;i<min+1;i—-){
if(x%i==0&&y%i==0){
return i;
}
}
}
最小公倍数
int LCM(int x,int y){
int max=(x>=y?x:y);
int i=max;
for(;i>1;i++){
if(i%x==0&&i%y==0){
return i;
}
}
}