Beispiel #1
0
int isFibonacci(long int n)
{
    if(isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4))
	return 1;
    else
	return 0;
}
Beispiel #2
0
bool isFibo(long long int n)
{
	long long int r1=(5*n*n)+4;
	long long int r1=(5*n*n)-4;
	if(isPerfectSquare(r1)||isPerfectSquare(r2))
		return true;
	else
		return false;
}
Beispiel #3
0
int main() {
    ullong total = 0;
    for(long long x = 0; x <= 5; ++x) {
        for(long long y = 0; y <= 5; ++y) {
            if((isPerfectSquare(y)) && (isPerfectSquare(x)) && (isPerfectSquare(x+y))) {
                ++total;
                std::cout << '(' << x << ", " << y << ")\n";
            }
        }
    }
    std::cout << total << "\nnCr: " << nCr(10, 5);
}
int main()
{
	ll x,y,z; // x>y>z
	for(ll i=1;;i++)
	{
		printf("i = %lld\n",i);
		ll sq1=i*i;
		for(ll j=1;;j++)
		{
			ll sq2=j*j;
			if((sq1+sq2)%2==0)
			{
				x=(sq1+sq2)/2;
				y=sq1-x;
				if(y<=0)
					break;
				if(x>y && y>0)
				{
					for(ll k=1;;k++)
					{
						ll sq3=k*k;
						z=sq3-x;
						if(z>0)
						{
							if(x>z && y>z)
							{
								if(isPerfectSquare(x-z) && isPerfectSquare(y-z) && isPerfectSquare(y+z))
								{
									printf("x,y,z = %lld %lld %lld\n",x,y,z);
									printf("the answer is : %lld\n",(x+y+z));
									return 0;
								}
							}
							else break;
						}
					}
				}
			}
		}
	}
	return 0;
}
 bool judgeSquareSum(int c) {
     if(c == 0) return true;
     int a = 1;
     while(a <= c / a) {
         int bSquare = c - a * a;
         if(isPerfectSquare(bSquare)) {
             return true;
         }
         a++;
     }
     
     return false;
 }
 int helper(int n, vector<int> & D){
     if(D[n]<INT_MAX) return D[n];
     if(isPerfectSquare(n)){
         D[n] = 1;
         return 1;
     }
     int min_perfect_sq = n; // worst case 1+1+..
     for(int k=1; (k*k)<=n; k++){ 
         min_perfect_sq = min(min_perfect_sq, helper(n-k*k, D)+1);
     }
     D[n] = min_perfect_sq;
     return min_perfect_sq;
 }
Beispiel #7
0
int put_max_numbers()
{
    int vretorno = 1;
    bool matched = true;

    while(matched)
    {
        matched = false;
        for(int i = 0; i < n_pegs ; i++)
        {
            if((pegs[i] == 0) || isPerfectSquare(pegs[i] + vretorno))
            {
                pegs[i] = vretorno;
                vretorno++;
                matched = true;
                break;
            }
        }
    }
    return vretorno;
}
Beispiel #8
0
bool EulerUtility::isPentagonal(llui n)
{
	return isPerfectSquare((24 * n) + 1) && ((llui)sqrt((24 * n) + 1) + 1) % 6 == 0;
}
bool isFibonacci(int n) {
	return isPerfectSquare(5 * n * n + 4) || isPerfectSquare(5 * n * n - 4);
}