标签:style blog class code c java
#include<iostream> #include<algorithm> #include<numeric> using namespace std; int helper1(int a[],int n) { int sum = accumulate(a,a+n,0); int sum2 = n*(n-1)/2; return sum-sum2; } int helper2(int a[],int n) { int bitor = a[0]^0; for(int i = 1;i< n;i++) { bitor ^= a[i]; bitor ^= i; } return bitor; } int main() { int a[] = {1,2,3,4,5,5}; cout<<helper1(a,6)<<endl; cout<<helper2(a,6)<<endl; }
有没有想过如果没有要求是连续的整形的话,怎么办?
关于等比数列和等差数列的求和公式和递归公式,你是不是要补补?
an=a1×q^(n-1);
an=a1+(n-1)d
前n项和公式:Sn=na1+n(n-1)d/2
若公差d=1时:Sn=(a1+an)n/2
标签:style blog class code c java
原文地址:http://www.cnblogs.com/berkeleysong/p/3735568.html