The Problem is Three is Crowd. Link is http://www.codechef.com/problems/CROWD My code is
include <iostream>
include <iomanip>
define ll unsigned long long
define mod 1000000007
using namespace std;
int main() {
ll t; cin>>t;
ll x,y,z,i;
while(t--)
{
z=0;
cin>>x;
if(x<3)cout<<"0\n";
else{
y=x-2; y=y%mod;
z=(y*(y+1)); z=z/2;
cout<<z%mod<<"\n";
}
}
return 0;
}
My Logic is that : Suppose there are 6 Houses First : (1,2,3) , (2,3,4) , (3,4,5) , (4,5,6) (i.e total=4 (6-2)) Second : (1,2,3,4) , (2,3,4,5) , (3,4,5,6) (i.e total=4+3) Third : (1,2,3,4,5) , (2,3,4,5,6) (i.e total=4+3+2) Fourth : (1,2,3,4,5,6) (i.e total=4+3+2+1)
Indirectly ,the answer is sum of no's from 1 to (no of Houses - 2) if no of houses>=3 else answer=0 Here it is 1 to 4, so answer is 1+2+3+4=10
For the Problem test cases : Input 3 : ans=1 4 : ans=1+2=3
But getting Wrong Answer ..Pls Help