# [T3](https://www.luogu.com.cn/problem/U549508)
1. 对于这题的方位直接磨4即可,在统计每边x和y的值。
2. 再循环t次,求出答案。
```cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=5e5+7;
int a[maxn];
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int n,t;
int sum=0;
signed main(){
cin>>n>>t;
for (int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i];
}
int pos=0;
int sx=0;
int sy=0;
for(int i=1;i<=n;i++){
sx+=dx[pos]*a[i];
sy+=dy[pos]*a[i];
pos=(pos+a[i])%4;
}
pos=0;
int tx=0,ty=0;
for (int i=1;i<=t;i++){
pos=(pos+(sum%4))%4;
if(pos==0){
tx+=sx;
ty+=sy;
}
if(pos==1){
tx+=sy;
ty-=sx;
}
if(pos==2){
tx-=sx;
ty-=sy;
}
if(pos==3){
tx-=sy;
ty+=sx;
}
}
cout<<abs(tx)+abs(ty)<<endl;
return 0;
}
T4
这题十分有趣,又是分段二分。
对于题目所求,我们可以利用唯一分解定理进行简化,n=a[1]^p1+到底。
但是时间复杂度还是太高了,对于更大的一些数据,我们可以先打出质数表来,再进行和二分。
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 7;
const int N = 4e4;
int prime[maxn];
bool vis[maxn];
int n, cnt;
void init(){
vis[0]=vis[1]=1;
for(int i=2;i<=N;i++){
if(!vis[i]){
prime[++cnt]=i;
for(int j=i+i;j<=N;j+=i){
vis[j]=true;
}
}
}
}
void solve(){
cin>>n;
int ans=1;
for (int i=1;i<=cnt;i++){
int tmp=0;
while(n%prime[i]==0){
n/=prime[i];
tmp++;
if(tmp==3){
tmp=0;
ans*=prime[i];
}
}
}
int l=1;
int r=1000000;
while(l<r){
int mid=(l+r)/2;
if (mid*mid*mid>=n){
r=mid;
}else{
l=mid+1;
}
}
if(l*l*l==n){
ans*=l;
}
cout<<ans<<"\n";
}
signed main(){
int T;
cin>>T;
init();
while(T--){
solve();
}
return 0;
}