#include
const int N = 1e6 + 5;
int tot, p[N];
bool flg[N];
void sieve(int n){
for(int i=2; i<=n; i++){
if(!flg[i]){
p[++tot] = i;
}
for(int j=1; j<=tot&&i*p[j]<=n; ++j){
flg[i*p[j]] = 1;
if(i%p[j]==0){
break;
}
}
}
}
long long phi(long long x){
long long ans = x;
for(int i=1; i<=tot&& 1ll*p[i]*p[i]; ++i){
if(x%p[i]){
continue;
}
ans = ans/p[i]*(p[i]-1);
while(x%p[i]==0){
x /= p[i];
}
}
if(x>1){
ans = ans / (x * (x - 1));
}
return ans;
}
int main() {
sieve(N - 5);
long long n, k;
scanf("%llld%lld", &n, &k);
k = (k + 1) / 2;
for(long long i=1; i<=k&&n>1; ++i){
n = phi(n);
}
printf("%lld\n", n%1000000007);
return 0;
}
#include
#include
using namespace std;
int work(int x){
int L = 0, R = -1, lst = -1; //L最高位 R最低位 lst上一位数
while(x){
int tmp = x % 10;
L = tmp;
if(R==-1){
R = tmp;
}
/*相邻来两位>7*/
if(lst!=-1){
if(abs(tmp-lst)>7){
return 0;
}
}
lst = tmp;
x /= 10;
}
/*最高位和最低位差值>2*/
return abs(R-L)>2;
}
int main(){
int cnt = 0;
for(int i=13930; i<=457439; i++){
cnt += work(i);
}
cout<<cnt;
return 0;
}
#include
using namespace std;
int main(){
//ans累计,now当前的那个数
long long ans = 1, now = 1, MOD = 1000000007ll;
for(int i=2; i<=30; i++){
now = now * (now + 5);
now %= MOD;
ans += now;
ans %= MOD;
}
cout << ans;
return 0;
}
n = 10 #跑道长度
role_style = ['>.wwws..s.','.>.wwws.s.','>>>>>s.m.m','>w.wss..s.']
for role in role_style:
v = 1
T = 0
t = 0
tc = 0
r_list = list(role)
for item in r_list:
if item == '.': #平地
if tc > 0 :
t = 1/v
else:
v = 1
t = 1 / v
elif item == 'w': #水坑
if tc > 0:
t = 1/v*2
else:
t = 1/0.5
elif item == '>': #加速
v = 2 #持续时间5s
t = 1/v
tc = 5 #持续时间5s
elif item == 's': #石块,原地停留一秒,变平地
if tc-1 > 0:
t = 1 + 1/v
else:
v = 1
t = 1 + 1/v
elif item == 'm': #魔物
if tc-2 > 0:
t = 2 + 1 / v
else:
v = 1
t = 2 + 1 / v
else:
print('输入有误')
tc =tc -t
T += t
print(T)
不会
num = 1
sum = 1
for i in range(2,31):
num = num*(num+5)
sum += num
print(sum%1000000007)
//937527335
from scipy.special import comb
k,a,b,l,r = 1,1,1,2,3
f1 = 1
f2 = 1
f_list = [f1,f2]
for f in range(r):
fn = a*f_list[-1] + b*f_list[-2]
f_list.append(fn)
G = 0
for i in range(l,r+1):
G += comb(f_list[i-1],k) #排列组合求和
print(int(G))
//3
不会
不会
题意:建一个n<=50的n*n的方阵里面有X,O和.你可以把.变为X,如果O的上下左右都为X那么O变为. 。找出.最多时.的数量。
题解:就直接找O的上下左右有3个以上X时就把其中的.变为X,然后把O变为.,一直循环到不会有改变时停止。然后再用连通图找出连通图中的O和.的数量,如果O>.时就把.全部变为X,O全变为.。最后便利计算.的数量。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f
const int N = 1e4+10;
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int flag=1;
const ll maxn=100005;
int z[4][2]={
{
1,0},{
0,1},{
-1,0},{
0,-1}};
int dep;
int x,y,n;
int X[4]={
1,0,-1,0};
int Y[4]={
0,1,0,-1};
bool vis[55][55];
struct node{
int x,y;
};
char a[N][N];int ii,jj;
int v[55][55]={
0};
int to=0;
void BFS(int xx,int yy)
{
memset(vis,0,sizeof(vis));
++to;
queue<node>q;
q.push({
xx,yy});
vis[xx][yy]=true;
v[xx][yy]=to;
while (!q.empty())
{
node tmp=q.front(); q.pop();
int l=tmp.x,r=tmp.y;
for(int i=0;i<4;i++)
{
int tx=l+X[i],ty=r+Y[i];
if(a[tx][ty]=='X') continue;
if(vis[tx][ty]) continue;
q.push({
tx,ty}),vis[tx][ty]=true;
v[tx][ty]=to;
}
}
}
void check(){
if (a[ii][jj]=='X')
dep++;
else
x=ii,y=jj;
}
void b(int i,int j){
dep=0;
for (int k = 0; k < 4; ++k) {
ii=i+z[k][0];
jj=j+z[k][1];
check();
}
if (dep>=3)
a[x][y]='X',a[i][j]='.',flag=0;
else
x=0,y=0;
}
int main()
{
string s;
int tot=0,len;
for (int i = 0; i <= 51; ++i) {
for (int j = 0; j <= 51; ++j) {
a[i][j]='X';
}
}
while (getline(cin,s))
{
++tot;
len=s.size();
for(int i=1;i<=len;i++)
a[tot][i]=s[i-1];
if(tot==len) break;
}
n=len;
while (1) {
flag=1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (a[i][j] == 'O')
b(i, j);
}
}
if (flag)
break;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(v[i][j]==0&&a[i][j]!='X')
BFS(i,j);
}
int ans=0;
for(int k=1;k<=to;k++)
{
int o=0,oo=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(v[i][j]==k){
if(a[i][j]=='O') o++;
else oo++;
}
}
if(o>oo) ans+=o;
else ans+=oo;
}
printf("%d",ans);
return 0;
}