HDU 4704 Sum 欧拉降幂
本文最后更新于 2105 天前,其中的信息可能已经有所发展或是发生改变。

内容纲要

题解

利用数学方法中的“隔板法”,不难知道结果就是
$\displaystyle\sum_{k=0}^{n-1}{{n-1}\choose{k}}$
这是二项式定理的展开式。所以,这道题就转换为求解$2^{n-1} \mod (10^9+7)$

AC代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <array>

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
string s;

ll quickpow(ll x, ll a) {
    ll ans = 1;
    while (a) {
        if (a & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        a >>= 1;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while (cin >> s) {
        ll n = 0;
        for (auto i:s) {
            n = (n * 10 + i - '0') % (mod - 1);
        }
        n = (n - 1 + mod - 1) % (mod - 1) + (mod - 1);
        cout << quickpow(2, n) << '\n';
    }
    return 0;
}

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇