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; }
代码君
时间: 2024-10-03 14:45:08