Isn't the number of triangles in level n just n*(n^2 + 6 n - 1)/6? Dave
On Mar 19, 2:47 pm, cegprakash <cegprak...@gmail.com> wrote: > i've modified my algorithm > but i'm getting wrong answer. someone help.. > > #include<iostream> > using namespace std; > unsigned long long start,end,arr[1000001],arr2[1000001]; > int main(){ > int j,t,i,n; > for(i=0;i<1000000;i++){ > arr[i]=i+1+arr[i-1];} > > for(i=0;i<1000000;i++) > { > arr[i]+=arr[i-1];} > > arr2[1]=1; > arr2[2]=3; > for(i=3;i<=1000000;i++){ > arr2[i]=(i*(i+1)/ > 2)+arr2[i-2];} > > cin>>t; > while(t--){ > cin>>n; > cout<<arr[n-1]+arr2[n-1]<<endl;} > return 0; > > > > }- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.