标签:multi std 包括 包含 超过 while tput mit 超时
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 308 Accepted Submission(s): 150
inline long long multi(long long x,long long y) { long long tmp=(x*y-(long long)((long double)x/mod*y+1.0e-8)*mod); return tmp<0 ? tmp+mod : tmp; }
AC code:
1 #include <bits/stdc++.h> 2 #define INF 0x3f3f3f3f 3 #define LL long long 4 using namespace std; 5 const LL mod = 1000000007; 6 7 inline long long multi(long long x,long long y) 8 { 9 long long tmp=(x*y-(long long)((long double)x/mod*y+1.0e-8)*mod); 10 return tmp<0 ? tmp+mod : tmp; 11 } 12 13 14 LL qpow(LL a, LL n) 15 { 16 LL res = 1; 17 while(n){ 18 if(n&1) res = multi(res, a)%mod; 19 a = multi(a, a); 20 n>>=1; 21 } 22 return res%mod; 23 } 24 25 26 int main() 27 { 28 // freopen("result.out", "w", stdout); 29 LL N, p, ans; 30 while(~scanf("%lld", &N)){ 31 p = qpow(2, N); 32 ans = (multi((N-1), p)%mod+1)%mod; 33 printf("%lld\n", ans); 34 } 35 36 return 0; 37 }
HDU 6467 简单数学题 【递推公式 && O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)
标签:multi std 包括 包含 超过 while tput mit 超时
原文地址:https://www.cnblogs.com/ymzjj/p/10547900.html