×

# PLZ HELP..HOW TO REDUCE TIME COMPLEXITY ??

 0 #include //#include int main() { //clrscr(); int t; long m,n,num,sum=0,lsum=0,i; scanf("%d",&t); while(t--) { scanf("%ld%ld",&m,&n); i=m; while(i<=n) { //num=i; while(i!=0) { num=i%10; i=i/10; if(num%2==0) sum=sum+2*num; else sum=sum+num; } lsum=lsum+(sum%10); i++; } } printf("\n%ld",lsum); return 0; } asked 20 Jul '12, 23:28 21●5●5●10 accept rate: 0% can you state the question for which you have coded this. (24 Jul '12, 21:50) Can you state the problem you are trying to solve? Also mention what is your current approach. Seems like a poorly framed question (?) (31 Jul '12, 02:25) this is the question..http://www.codechef.com/problems/LASTDIG (01 Aug '12, 16:29)

 1 You are dividing the i: i/=10. This means that i is always set back to 1 at the end of the loop. You should use a temporary variable for the dividing. Like this:  while(i<=n){ int temp=i; while(temp!=0){ num=temp%10; temp/=10; } i++; }  P.S.: There are many other errors in your code in solving the stated problem.But they are not connected with the infinite looping. answered 02 Aug '12, 16:24 16●1●4 accept rate: 0%
 0 instead of i=i/10 use 1/=10; sum+=(num<<1); and a few more like this,but it won't really help much give the link of the file you have problem with or the question so we can try too answered 24 Jul '12, 22:26 1●2●2●3 accept rate: 0%
 -2 while(t--), there is no condition declared within while loop answered 29 Jul '12, 11:58 0★kssantoo -1 accept rate: 0% 1 it's c so when t-- will be 0 it'll exit (30 Jul '12, 14:50)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×263
×141

question asked: 20 Jul '12, 23:28

question was seen: 4,651 times

last updated: 02 Aug '12, 16:24