You are not logged in. Please login at www.codechef.com to post your questions!

×

PLZ HELP..HOW TO REDUCE TIME COMPLEXITY ??

#include <stdio.h> //#include <conio.h> 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

rakkuc007's gravatar image

2★rakkuc007
215510
accept rate: 0%

can you state the question for which you have coded this.

(24 Jul '12, 21:50) tapasweni4★

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) rizwanhudda5★
(01 Aug '12, 16:29) rakkuc0072★

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.

link

answered 02 Aug '12, 16:24

tapasweni's gravatar image

4★tapasweni
1614
accept rate: 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

link

answered 24 Jul '12, 22:26

bladeshark's gravatar image

2★bladeshark
1223
accept rate: 0%

-2

while(t--), there is no condition declared within while loop

link

answered 29 Jul '12, 11:58

kssantoo's gravatar image

0★kssantoo
-1
accept rate: 0%

1

it's c so when t-- will be 0 it'll exit

(30 Jul '12, 14:50) bladeshark2★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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:

×214
×108

question asked: 20 Jul '12, 23:28

question was seen: 4,321 times

last updated: 02 Aug '12, 16:24