Chef and Segments

I have used the idea of fenwick trees to solve this problem.
ans=tree[r]/tree[l-1];
I am getting wrong answer.Please help!!Thanks in advance.

problem-http://www.codechef.com/problems/CHMOD
my solutin link- http://www.codechef.com/viewsolution/3974041