Witam, zaczynam dopiero uczyć się programowania i robię zadanie z pewnej strony. Link do zadania https://pl.spoj.com/problems/PA05_POT/ .
To jest mój kod, zauważyłem, że np. dla liczby 111112^3 podaj mi złą cyfrę jedności i nie wiem dlaczego.
#include <iostream>
using namespace std;
int i=0,a,p,w,d;
int jednosci(int p, int w){
if(p==0)
return 0;
else if(w==0)
return 1;
else if(p==1)
return 1;
else if(p==2)
if(w%5==0)
return 2;
else if(w%4==0)
return 6;
else if(w%3==0)
return 8;
else if(w%2==0)
return 4;
else if(w%1==0)
return 2;
else if(p==3)
if(w%5==0)
return 3;
else if(w%4==0)
return 1;
else if(w%3==0)
return 7;
else if(w%2==0)
return 9;
else if(w%1==0)
return 3;
else if(p==4)
if(w%3==0)
return 4;
else if(w%2==0)
return 6;
else if(w%1==0)
return 4;
else if(p==5)
return 5;
else if(p==6)
return 6;
else if(p==7)
if(w%5==0)
return 7;
else if(w%4==0)
return 1;
else if(w%3==0)
return 3;
else if(w%2==0)
return 9;
else if(w%1==0)
return 7;
else if(p==8)
if(w%5==0)
return 8;
else if(w%4==0)
return 6;
else if(w%3==0)
return 2;
else if(w%2==0)
return 4;
else if(w%1==0)
return 8;
else if(p==9)
if(w%3==0)
return 9;
else if(w%2==0)
return 1;
else if(w%1==0)
return 9;
}
int main()
{
cin>>d;
for( i=0; i<d; i++ ){
cin>>p>>w;
a==p%10;
cout<<jednosci(a,w);
}
return 0;
}
Z góry dziękuję za pomoc.