Skip to content

Instantly share code, notes, and snippets.

@ukasiu
Last active December 25, 2015 12:49
Show Gist options
  • Select an option

  • Save ukasiu/6979700 to your computer and use it in GitHub Desktop.

Select an option

Save ukasiu/6979700 to your computer and use it in GitHub Desktop.
No, mała liczba, to sprawdziłem metodą dość brutalną podstawiając pod modulo dość dużą potęgę 10 i też mi wyszło 8. Pytanie tylko jak zrobić krótki a zarazem poprawny kod ;)
#include<iostream>
#define ULL unsigned long long
using namespace std;
ULL tenn(ULL n) {
ULL w=1,ten=1;
while(w<=n) {
w*=5; ten*=10;
}
return ten;
}
int main() {
ULL n;
cout << "Podaj n" << endl;
cin >> n;
ULL modulo=tenn(n);
ULL wynik=1;
for(int i=1;i<=n;i++) {
wynik *= i;
while(wynik%10==0) {
wynik /= 10;
}
wynik %= modulo;
}
cout << wynik%10 << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment