eng
competition

Text Practice Mode

Chương trình C++ kiểm tra số Fibonacci

created Sep 27th 2023, 14:56 by WeirdMing


0


Rating

94 words
6 completed
00:00
#include <bits/stdc++.h>
 
using namespace std;
 
bool isPerfectSquare(long long x) {
    long long sqrtX = sqrt(x);
    return sqrtX * sqrtX == x;
}
 
bool isFibonacci(long long n) {
    return isPerfectSquare(5 * n * n + 4) || isPerfectSquare(5 * n * n - 4);
}
 
int main() {
    long long x,y;
    cin >> x;
    for (int i = 0; i < x; i++) {
        cin >> y;
        if (y == 0) {
            cout << "IsFibo\n";
        } else if (isFibonacci(y)) {
            cout << "IsFibo\n";
        } else {
            cout << "IsNotFibo\n";
        }
    }
    return 0;
}
 

saving score / loading statistics ...