calculation hoj2901

/*This Code is Submitted by billforum for Problem 2901 at 2012-05-24 16:25:02*/

#include<iostream>
#include<stdio.h>

#include<string.h>
using namespace std;
long long cal(long long x,long long b,long long a)
{
        long long c=x,tmp=1;
        while(b>0)
        {
                if(b&1==1) tmp=(tmp*c)%a;
                b=b>>1;
                c=(c*c)%a;
        }
        return tmp;
}
int main()
{
        long long a,b;
        while(cin>>a>>b)
        {
                if(a%2==0)
                {
                        cout<<cal(a/2,b,a)<<endl;
                }
                else cout<<"0"<<endl;
        }
        

        return 0;
}

  

posted @ 2012-05-24 16:33  wuzhibin  阅读(141)  评论(0编辑  收藏  举报