码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4704 Sum( 费马小定理 )

时间:2014-10-28 00:29:36      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   ar   for   sp   

 

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;
}
代码君

 

HDU 4704 Sum( 费马小定理 )

标签:style   blog   http   io   color   os   ar   for   sp   

原文地址:http://www.cnblogs.com/BigBallon/p/4055525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!