之前做的一次题目,挺有意思的就贴上来 https://atcoder.jp/contests/arc135/tasks/arc135_a 这里我用的是记忆化递归的思路,减少复杂度(虽然我还不太会怎么算_)
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod=998244353;
map<ll,ll>sum;
ll num(ll x)
{
if(x==1||x==2||x==3||x==4)
{
sum[x]=x;
return x;
}
if(x%2==0)
{
ll p=x/2;
if(sum.find(p)==sum.end())
{
sum[p]=num(p);
}
return sum[p]*sum[p]%mod;
}
if(x%2==1)
{
ll p=x/2;
if(sum.find(p)==sum.end())
{
sum[p]=num(p);
}
if(sum.find(p+1)==sum.end())
{
sum[p+1]=num(p+1);
}
return sum[p]*sum[p+1]%mod;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
ll x;
cin>>x;
cout<<num(x)%mod;
return 0;
}
|