Problem is to find the last digit of the number (1358)^n. I've used the same method in c++ with two different compilers but the results are different in both the compilers on codeforces.
Compilers: clang c++17 Diagnostics(code accepted) but with GNU G++17 verdict is wrong_answer.
I'm not getting where the problem is, and why the results are different for both the compilers?
n = [0, 1000000000]
Test cases: 1000000000, 32, 33, 36
correct answer: 6, 6, 8, 6
but with GNU Compiler: 1, 1, 8, 6
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double n; cin >> n;
    vector<long long> res{ 1, 8, 4, 2, 6 };
    if (n <= 4){
        cout << res[n] << "\n";
    }
    else{
        while (n > 4){
            double x = log10(n)/log10(2);
            n = (ceil(x) == floor(x))? 4 : n - pow(2, floor(x));
        }
        cout << res[n] << "\n";
    }
    return 0;
}
 
    