Re: [algogeeks] Spoj-merectcnt

2011-03-20 Thread Ankur Khurana
problem ka link bhi diya karo ya code..

On Sun, Mar 20, 2011 at 3:34 AM, sunny sunny.verma...@gmail.com wrote:

 hello frnds...
 i am getting TLE in 12th test case ..
 can anyone over ther help me to shorten it..
 #includestdio.h
 #includeiostream
 using namespace std;
 int gcd(int a, int b)
 {  if(b==0)
return(a);
   else
   return gcd(b,a%b);

 }
 int main()
 {
int rec,g,count=0;
scanf(%d,rec);
for(int i=1;i=rec;i++){
for( int j=i;j=1;j--){
if((i+j)rec){
  g=gcd(i,j);
  if((i+j-g)==rec){
 count++;

  }
}
else
 break;
}
}
printf(%d,count);
return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Spoj-merectcnt

2011-03-19 Thread sunny
hello frnds...
i am getting TLE in 12th test case ..
can anyone over ther help me to shorten it..
#includestdio.h
#includeiostream
using namespace std;
int gcd(int a, int b)
{  if(b==0)
return(a);
   else
   return gcd(b,a%b);

}
int main()
{
int rec,g,count=0;
scanf(%d,rec);
for(int i=1;i=rec;i++){
for( int j=i;j=1;j--){
if((i+j)rec){
  g=gcd(i,j);
  if((i+j-g)==rec){
 count++;

  }
}
else
 break;
}
}
printf(%d,count);
return 0;
}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.