Witam!
Mam problem, otóż internetowy sędzia kazał mi wypisać k razy (1 <= k <= 10) ostatnią liczbę potęgowania (1 <= a,b <= 1000000000). Program, który napisałem działa, ale z niewiadomych przyczyn sędzia nie chce go zaliczyć
#include <iostream>
#include <vector>
using namespace std;
int pow(int a, int b)
{
if (b == 0) return 1;
else if (b == 1) return a%10;
else if (a%10 == 0) return 0;
vector<int> last;
bool found = false;
last.push_back(0);
unsigned long long int x = 1;
int pattern = 0;
for (int i=0; i<b; i++)
{
x*=a;
int y = x%10;
for (int j=0; j<last.size(); j++)
{
if (last[j] == y) found = true;
}
if (!found) last.push_back(y);
if (found) break;
pattern++;
}
unsigned long int mod;
if (b%pattern == 0) mod = pattern;
else mod = b%pattern;
return last[mod];
}
int main()
{
int x;
cin >> x;
int* a = new int[x];
int* b = new int[x];
for (int i=0; i<x; i++) cin >> a[i] >> b[i];
for (int i=0; i<x; i++)cout << pow(a[i], b[i]) << endl;
return 0;
}
Czego nie wziąłem pod uwagę?