Topic Link: Click to open the link
Test instructions
The Martian counting rule only a,b,c,d four letters, counting rules from small to large is a,b,c,d,aa,ab,ac,ad,ba, .... Give a Martian figure consisting of four letters from A,b,c,d, and figure out the number (starting from 1). Equivalent to 5 binary.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 10000002#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int> #define ull unsigned long Longu Sing namespace Std;char s[1010];ll pow_mod (ll a,ll n,ll p) {if (n==0) return 1; ll Ans=pow_mod (a,n/2,p); Ans=ans*ans%mod; if (n&1) Ans=ans*a%mod; return ans;} void Solve () {ll len=strlen (s), ans=0; for (ll i=0;i<len;i++) {ll d=s[i]-' a ' +1; Ans= (ans+ (D*pow_mod (4,len-i-1,mod))%mod)%mod; } printf ("%lld\n", ans);} int main () {int t;scanf ("%d", &t), while (t--) {scanf ("%s", s); Solve ();} return 0;}
Sdut 2502-Mars counting method (fast power)