Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Wednesday, April 2, 2014

WPC5B-Crypto

Crypto

given below code is for wpc5b spoj or crypto spoj.
Here no need of explanation every number multiplied with itself get repeated after some interval .So here just calculate the interval.
.. Happy Coding ..
#include <bits/stdc++.h>
using namespace std;
#define MOD 10
int main()
{
 long long t;
 int temp,m;
 int res[10][5]={{0,0,0,0,1},
                 {1,1,1,1,1},
                 {6,2,4,8,4},
                 {1,3,9,7,4},
                 {6,4,0,0,2},
                 {5,0,0,0,1},
                 {6,0,0,0,1},
                 {1,7,9,3,4},
                 {6,8,4,2,4},
                 {1,9,0,0,2},
    };
 scanf("%lld",&t);
 while(t--)
 {
  long long a,b;
  scanf("%lld%lld",&a,&b);
  if(b==0){
   printf("1\n");
   continue;}
  temp = a % MOD;
  m = b%res[temp][4];
  printf("%d\n",res[temp][m]);
 }
 return 0;
}