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

×

polo the penguin and numbers--TLE

#include<stdio.h>

int no_dig(long long a){

  if(a<10)

   return 1;

if(a<100)

   return 2;

if(a<1000)

   return 3;

if(a<10000)

   return 4;

if(a<100000)

   return 5;

if(a<1000000)

   return 6;

if(a<10000000)

   return 7;

if(a<100000000)

   return 8;

if(a<1000000000)

   return 9;
if(a==1000000000)

   return 10;
}

int main(){


 int t=0;

long long c,d,i,sum=0;

scanf("%d",&t);

while(t-- > 0){

  scanf("%lld %lld",&c,&d);

  for(i=c;i<=d;i++){

     sum=(sum%1000000007+(i%(1000000007)*(no_dig(i)%1000000007))%1000000007)%1000000007;
 }

 printf("%lld\n",sum);

 sum=0;

} //getch(); return 0;

}

//here the main reason for TLE is for teh time taken to count the number of digits in a number.what is the efficient way to count the number of digits

asked 16 Mar '15, 10:56

aniruddha_paul's gravatar image

2★aniruddha_paul
35213
accept rate: 0%

edited 16 Mar '15, 10:58

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:

×3,820
×1,490
×729

question asked: 16 Mar '15, 10:56

question was seen: 636 times

last updated: 16 Mar '15, 10:58