hanoi双塔问题

思路

递推鸟题

\[F_0=0\\ F_1=1\\ F_n=2F_{n-2}+2 \]

蒟蒻代码

#include <bits/stdc++.h>
#define re register
using namespace std;
typedef long long ll;

const int N=410;
int n;
ll ans[N];

void make_table(){
    ans[0]=0; ans[1]=1;
    for(re int i=1;i<=405;i++)
        ans[i]=2*ans[i-2]+2;
}

int main()
{
    ios::sync_with_stdio(0);
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
#endif
// ======================================================================
    make_table();
    cin>>n;
    cout<<ans[n<<1];

// ======================================================================
end:
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
    return 0;
}

天使的起誓

思路

m 每位处理,利用 mod 运算性质

蒟蒻代码

#include <bits/stdc++.h>
#define re register
using namespace std;

const int N=1e3+10;
int n;
int ans=0;
string m;
int base=1;

int main()
{
    ios::sync_with_stdio(0);
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
#endif
// ======================================================================
    cin>>n>>m;
    for(re int i=m.length()-1;i>=0;i--){
        ans=(ans+(m[i]-'0')*base)%n;
        base=base*10%n;
    }
    if(!ans) cout<<n;
    else cout<<ans;

// ======================================================================
end:
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
    return 0;
}