HDU 4704 Sum( 费马小定理 )

时间:2014-10-28 00:29:36   收藏:0   阅读:234

 

HDU 4704 Sum( 费马小定理 )

 

理解能力果然拙计,,题目看半天没懂什么意思。

 

bubuko.com,布布扣

 

  bubuko.com,布布扣

 

bubuko.com,布布扣
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define MOD 1000000007

char str[100010];

LL fast_mod( LL a, int b)
{
    LL res = 1;
    while( b )
    {
        if( b & 1 )    res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

void Orz()
{
    while( ~scanf( "%s", str ) )
    {
        LL n = 0;
        for( int i = 0; str[i]; ++i )
            n = ( n * 10 + str[i] - 0 ) % ( MOD - 1 );
        printf( "%I64d\n", fast_mod( 2, n - 1 ) );
    }
}

int main()
{
    Orz();
    return 0;
}
代码君

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!