參考
https://www.nowcoder.com/discuss/88837?type=101
有規律了直接寫就行了
歐拉函數學習見 :https://blog.csdn.net/qq_37493070/article/details/81988725
代碼(看懂算你厲害,手動滑稽 ^_^)
#include<bits/stdc++.h>
using namespace std;
#define _______ long long
#define __________ double
#define ___________(a) scanf("%d",&a)
#define ____________(a) scanf("%s",a)
#define _______________ for
const _______ _____________=3e5+10;
const _______ ______________ =1e9+7;
map<_______,_______>________;
_______ ______(_______ _){
int __=_;
for(int ___=2;___*___<=_;___++){
if(_%___==0){
__=__-__/___;
while(_%___==0) _/=___;
}
}
if(_!=1) __=__-__/_;
return __;
}
void ____(){
_______ _=______________;
while(_!=1){
________[_]=______(_);
_=________[_];
}
________[1]=1;
}
_______ ______(_______ _,_______ __,_______ ___){
_______ ____=1;
while(__){
if(__&1) ____=(____*_)%___;
__>>=1;
_=(_*_)%___;
}
return ____;
}
char ___[_____________];
_______ ____(_______ _,_______ __){
if(_==-1) return 0;
else if(___[_]=='0') return (____(_-1,__)+1)%__;
else if(___[_]=='1') return (2*____(_-1,__)+2)%__;
else return (3*______(2,____(_-1,________[__])+1,__)-3+__)%__;
}
int main(){
____();
int _;
___________(_);
while(_--){
____________(___);
printf("%lld\n",____(strlen(___)-1,______________)%______________);
}
return 0;
}