链接:P6392 中意 - 洛谷
题目:
思路:
数论这一块
题目让我们求这个结果对 MOD 取模,那么我们肯定是不像看到这个除法,所以考虑如何消除这个除法
我们可以想到,向上取整就是加上一个数,假设其为 x,那么原式就可以变成
,此时就能将 25 化简掉。即变成
那么问题就变成了如何求这个 x,很显然,这个 x 就是 25 减去 对 25 取模的结果
那么如何求得这个结果呢?
所以我们可以拆开来求,具体步骤写代码中了
然后求得 x 后按照上面的公式计算即可,特别注意要使用快速幂加速运算
代码:
#include <iostream>
#include <algorithm>
#include<cstring>
#include <iomanip>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <utility>
#include <array>
#include <tuple>
using namespace std;
#define int long long
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
const int MOD = 998344353;int qp(int a,int b,int mod)
{int res = 1;while (b){if (b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res % MOD;
}int change(const string & s)
{int ans = 0;for (auto & c : s){ans *= 10;ans += c - '0';ans %= MOD;}return ans;
}void solve()
{string s; int a;cin >> s >> a;int b = change(s);int mowei = s.back() - '0';if (s.size() > 1){mowei += (s[s.size() - 2] - '0') * 10;}mowei *= qp(2, a + 2, 25);mowei %= 25;mowei = (25 - mowei) % 25;mowei *= 4;int newa = qp(2, a + 2, MOD);int first = b * newa % MOD * 4 % MOD;int second = mowei % MOD;cout << (first + second) % MOD << endl;
}
signed main()
{//cin.tie(0)->sync_with_stdio(false);int t = 1;//cin >> t;while (t--){solve();}return 0;
}