搞不懂细节的快速幂模板题
  • 板块P6392 中意
  • 楼主LemonLime
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/8/1 21:14
  • 上次更新2023/11/6 21:33:19
查看原帖
搞不懂细节的快速幂模板题
367190
LemonLime楼主2020/8/1 21:14

题目要求:

b×2a+225×100mod998344353\lceil\dfrac{b\times 2^{a+2}}{25}\rceil\times 100 \bmod998344353

所以问题在于:

  • 向上取整为什么不可以用 std::ceil()
  • 只能过 subtask 1,其它全 WA。求 debug。

轻喷楼主这个弱智。若能解答感恩不尽。

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
using namespace std;

typedef long long ll;
const ll MOD=998344353LL;
ll a,b;

ll _stoi(string s)
{
	ll res=0;
	for(auto ch:s)
	 res=(res*10+int(ch-'0'))%MOD;
	return res%MOD;
}

ll qpow(ll base,ll k)
{
	ll res=1;
	while(k)
	{
		if(k&1)
		 res=res*base%MOD;
		k>>=1;
		base=base*base%MOD;
	}
	return res%MOD;
}

int main()
{
	ios::sync_with_stdio(false);
	string st;cin>>st>>a;
	b=_stoi(st);
	ll tmp=b*qpow(2,a+2)%MOD;
	ll i=0;
	for(;i<=24;i++)
	 if((tmp+i)%25LL==0)
	 {
		 tmp+=i;
		 break;
	 }
	cout<<(tmp*4%MOD)<<endl;
	// ll ans=(ll)(ceil(tmp/25.0))*100LL%MOD;
	// cout<<ans<<endl;
	return 0;
}

2020/8/1 21:14
加载中...