小x的奇遇-adventure

http://oj.saikr.com/problem/IPC3-A

 

 

 

 

 

 

 

 

#include <bits/stdc++.h>
#define inf 2333333333333333
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(long long i=a;i<=b;++i)
//by war
//2020.11.17
using namespace std;
long long T,n,k,m,t,mod=1000000007;
void in(long long &x){
    long long y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(long long x){
    if(x<0){p('-');x=-x;}
    if(x>9)o(x/10);
    p(x%10+'0');
}

long long eular(long long x){
    long long ans=x;
    t=sqrt(x);
    For(i,2,t){
        if(x%i==0) ans=ans/i*(i-1);
        while(x%i==0) x/=i;
    }
    if(x>1) ans=ans/x*(x-1);
    return ans;
}

signed main(){
    in(T);
    while(T--){
        in(n);in(k);
        m=(k+1)/2;
        for(long long i=1;i<=m && n>1;i++){
            n=eular(n);
        }
        o(n%mod);p('\n');
    }
    return 0;
}

 

posted @ 2020-11-17 10:59  WeiAR  阅读(237)  评论(0编辑  收藏  举报