newercoder contest4

newcoder contest4

A 指数循环节

题解

打表的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6+10;
const int mod = 1e9+7;
int main(){
ios::sync_with_stdio(false);
string s;
while(cin>>s){
string t;
t.clear();
int tot = 0;
while(s.length()!=0){
t.clear();
for(int i=0; i<s.length(); i++){
if(s[i] == '0') t+=s[i];
else if(s[i] == '1') t+=s[i], t+='0';
else t+=s[i], t+='1';
}
tot++;
t = t.substr(1, t.length());
cout<<s<<" "<<t<<endl;
s = t;
}
cout<<tot<<endl;
}
return 0;
}

ac code

相对欧拉公式进行一些说明:
\(a^b = a^{b \% phi(n)+phi(n)}(mod n)(b \gt phi(n))\),这里不要求a, n互质。这个公式是错误的!不要加后面的phi(n)
变形:
\(a^b = a^{(b+phi(n)) \% phi(n)}(mod n)\) 无后面的条件了!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
typedef long long ll;
const int modd = 1e9+7;
map<ll, ll> mp;
char s[maxn];
ll euler(ll x){
if(mp.count(x)) return mp[x];
ll ans = x;
ll temp = x;
for(int i=2; i*i<=x; i++){
if(x%i ==0){
ans -= ans/i;
while(x%i == 0){
x /= i;
}
}
}
if(x>1){
ans -= ans/x;
}
mp[temp] = ans;
return ans;
}
ll pow_mod(ll a, ll b, ll c){
ll ans = 1;
while(b){
if(b&1) ans = ans*a%c;
a = a*a%c;
b>>=1;
}
return ans;
}
ll dfs(ll x, ll mod){
if(x<0 || mod == 1) return 0;
//cout<<s[x]<<" "<<x<<" "<<mod<<endl;
if(s[x] == '0'){
return (dfs(x-1, mod)+1ll)%mod;
}
else if(s[x] == '1'){
return (2ll*dfs(x-1, mod)+2ll)%mod;
}
else if(s[x] == '2') {
return (6ll*pow_mod(2, (dfs(x-1, euler(mod))+euler(mod))%euler(mod), mod)%mod-3ll+mod)%mod;
}
return 0;
}
int main(){
ios::sync_with_stdio(false);
//cout<<euler1(1e9+7)<<endl;
int t;
scanf("%d", &t);
ll mi;
mp.clear();
while(t--){
scanf("%s", s);
printf("%lld\n", dfs(strlen(s)-1, 1e9+7));
}
return 0;
}

G 删数问题

J 反向hash

未解决的问题

文章目录
  1. 1. A 指数循环节
    1. 1.1. 题解
      1. 1.1.1. 打表的代码
    2. 1.2. ac code
  2. 2. G 删数问题
  3. 3. J 反向hash
  4. 4. 未解决的问题
{{ live2d() }}