samedi 28 mars 2015

i am doing this codechef http://ift.tt/1a4H115 , i am getting run time error , it works fine on dev c++ compiler



actually , the problem is described below:


Chef's kid, Junior chef loves playing with different series. Chef, impressed by his son's curiosity, gifts him a special series S on his birthday S=1,2,-2,3,-3,3,4,-4,4,-4,............. Now chef, eager to check the intelligence of his son, gives him q queries to solve. Each query consists of two positions a and b, and Junior_chef is required to calculate the sum of all integers from a to b. Input


The first line of the input contains a single integer q, which denotes the number of queries. Next q lines consist of two integers, a and b. Output


Print the answer in single line. Constraints


1<=q<=10 , 1<=a,b<=10^12 Sample Input


1 1 4 Sample Output


4 Explanation : As the series is 1,2,-2,3, therefore the sum will be 4.



please do help

#include<iostream>
using namespace std;
main()
{
int t;
long int i,j,sum,number,temp,number2,tempi,count,a,b;
cin>>t;
while(t--)
{
count=0;
number2=1;
cin>>a>>b;
i=b;
long int str[b];
j=0;
tempi=i;
while(i--)
{
temp=number2;
number=number2;
while(temp--)
{
str[j]=number;
j++;
count++;
number=number*-1;
if(count==tempi)
break;
}
if(count==tempi)
break;
number2++;
}
sum=0;
for(i=a-1;i<=b-1;i++)
sum=sum+str[i];
cout<<sum<<endl;
}
}



Aucun commentaire:

Enregistrer un commentaire