Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Amitere Iasi S2 Ex3
- #include <iostream>
- using namespace std;
- int ultimaCifraFactorial(int n)
- {
- int S = 1;
- for( int i = 2; i <= n; i++ ){
- S = (S * i )% 10;
- }
- return S;
- }
- unsigned long long int calc(int a)
- {
- int k = 0, n, c;
- n = a;
- while(n != 0 && k != 4){
- c = n % 10;
- n /= 10;
- if( c == 0 ){
- return -1;
- }
- k++;
- }
- if(k!=4){
- return -1;
- }
- ///
- int m = 0, copie = a, p1 = 1,p2 = 1;
- n = 0;
- k = 1;
- while(a != 0){
- c = a % 10;
- a /= 10;
- if( k % 2 == 1 ){
- n = n + p1 * c;
- p1 *= 10;
- }
- else{
- m = m + p2 * c;
- p2 *= 10;
- }
- k++;
- }
- a = copie;
- ///
- unsigned long long int rezultat = n, S = 1; /// n^m
- for( int i = 1; i < m; i++ ){
- rezultat *= n;
- }
- for( int i = 2; i <= n; i++ ){ /// n!
- S *= i;
- }
- rezultat += S;
- rezultat--;
- if( rezultat % 10 == 0 ){
- return 1;
- }
- else{
- return 0;
- }
- }
- int main()
- {
- int n, m;
- cin >> n;
- cout << ultimaCifraFactorial(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement