HDU 4704 Sum( 费马小定理 )

 

HDU 4704 Sum( 费马小定理 )

 

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

 

HDU 4704 Sum( 费马小定理 )

 

  HDU 4704 Sum( 费马小定理 )

 

#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)