分析:因为按位或最后肯定小于等于加,所以把所有数按位或即可
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 using namespace std; 5 const int maxn=1e5+10; 6 long long a[maxn]; 7 int T,n; 8 int main() 9 { 10 cin>>T; 11 while(T--) 12 { 13 scanf("%d",&n); 14 long long res=0; 15 for(int i=1;i<=n;i++){ 16 cin>>a[i]; 17 res|=a[i]; 18 } 19 cout<<res<<endl; 20 } 21 return 0; 22 }
Chang and the Perfect Function
分析:我们求出每一个sqrt(i*i+y)-i,最后加起来即可
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "string" 5 #include "cmath" 6 using namespace std; 7 long long a,b; 8 int main() 9 { 10 cin>>a>>b; 11 long long d=0; 12 for(long long i=1;i<=a;i++){ 13 long long res=i*i+b; 14 long long c=sqrt(res); 15 d+=c-i; 16 } 17 cout<<d<<endl; 18 }