1 solutions

  • 1
    @ 2025-3-22 10:20:50
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1010;
    int f[N][2];///f[i][0] 表示偶数个3的方案数,f[i][1]表示奇数个3的方案数 
    int main()
    {
        int n;
        cin>>n;
        f[1][0]=9; 
    	f[1][1]=1;
        int t=9;
        for(int i=2;i<=n;i++)
        {
            if(i==n) t=8; //最高位不能为0 
            f[i][0]=(f[i-1][0]*t+f[i-1][1])%12345;
            f[i][1]=(f[i-1][1]*t+f[i-1][0])%12345;
        }
        cout<<f[n][0];
        return 0;
    }
    • @ 2025-3-22 10:24:43
      /*#include <iostream>
      #include <cstdio>
      #include <cmath>
      #include <cstring>
      #include <cstdlib>
      #include <cstring>
      #include <stack>*/
      #include <bits/stdc++.h>
       
      #define A 1000+5
       
      using namespace std;
       
      const int maxn=1000+5;
      int cnt;
      int a[maxn];
      int i,j;
       
      int main()
      {
          int n;
          cin>>n;
       
          if(n==1) cout<<9<<endl;
       
          int x=9;
          a[1]=9;
          long long de=10;
          for(i=2;i<=n;i++)
          {
              a[i]=(8*x+de-x)%12345;
              x=x+a[i];
              de=de*10%12345;//因为 n 最大为1000 所以赶紧求余吧,要不指数爆炸别怪我
          }
          cout<<a[n];
          return 0;
      }

Information

ID
1003
Time
1000ms
Memory
256MiB
Difficulty
5
Tags
(None)
# Submissions
11
Accepted
5
Uploaded By