请问各位大佬,为什么下面两段代码等价?
//1
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,t,t2,ans;
void f(){
switch (n%5) {
case 1:
cout<<20;
break;
case 2:
cout<<40;
break;
case 3:
cout<<80;
break;
case 4:
cout<<40;
break;
default:
cout<<20;
break;
}
cout<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int nn; cin>>nn;
for(int i=0;i<nn;i++){
cin>>n;
if(n<1)n=1-n;
if(n<4){
f();
continue;
}
t=(n-3)/5;
ans=t*(t+1)/2*5;
t2=n-t*5-3;
t++;
ans+=t2*t;
cout<<ans;
f();
}
return 0;
}
//2
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n,a;
cin>>n;
for(int i=0;i<n;i++){
cin>>a;
cout<<10*a*a-10*a+20<<'\n';
}
return 0;
}
这道原题是有唯一解的
原题来自石门电竞团队