Page 1 of 1
11970 - Lucky Numbers
Posted: Sat Apr 16, 2011 3:10 pm
by truewt
Can anybody help??? My code is TLE sadly.. Is there any tricks to the search space?
Re: 11970 - Lucky Numbers
Posted: Sun Apr 17, 2011 5:40 am
by asif_iut
for the result of the given equation to be an integer, the denominator must be an integer. So, the numbers in the denominator must be a square number ( n * n ) . Now, generate all possible square numbers between 10^9 and search for possible answers.
Hope it helps
Re: 11970 - Lucky Numbers
Posted: Sun Apr 17, 2011 6:07 am
by iriz7482
I only need to find all divisor of input number n in the range [1,(int)sqrt(n)) and for each divisor I print the answer
for example, there are 2 divisors of 16 in the range [1,4) so output 2 numbers
Moreover, I didn't use long long and long double, long is enough

and your code is much more complex than mine

Re: 11970 - Lucky Numbers
Posted: Sun Apr 17, 2011 9:43 am
by truewt
Thanks folks for such quick response! Managed to get AC after some thinking using iriz7482 method

Re: 11970 - Lucky Numbers
Posted: Wed May 04, 2011 8:35 pm
by blckhrt
here is my code..got tle..help meeee
#include<stdio.h>
#include<math.h>
int main()
{
unsigned long int c,i,n,q,d,j,m,ruh[100],sq;
while(scanf("%lu",&c)==1)
{
for(j=1;j<=c;j++)
{
scanf("%lu",&n);
printf("\nCase %lu:",j);
sq=(long int)sqrt(n);
for(i=sq;i<n;i++)
{
q=n-i;
d=(long int)sqrt(q);
if((q==d*d)&&(i%d==0))
printf(" %lu",i);
}
}
}
return 0;
}
Re: 11970 - Lucky Numbers
Posted: Thu May 19, 2011 10:12 pm
by kalochita
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int T;
cin>>T;
long long N,x,s;
for(int j=1;j<=T;j++)
{
cin>>N;
long rt=sqrt(N-1);
cout<<"case "<<j<<":";
for(long i=rt;i>=1;i--)
{
s=i*i;
x=N-s;
if(x%i==0)
cout<<" "<<x;
}
if(j!=T)
cout<<"\n";
}
return 0;
}
here is my code. the feedback is 'wrong answer'. what's the problem? pls help me.
Re: 11970 - Lucky Numbers
Posted: Sun Jun 05, 2011 8:35 pm
by robot
Hi Kalochita...
Please be careful of problem statement ....you have in simple mistake..
1. change: case->Case
2.if(j!=T) //no need
always print a new line .
I hope u will get Accepted..
ASU(SUST)

Re: 11970 - Lucky Numbers
Posted: Thu May 28, 2015 10:20 pm
by Maqsud
I don't understand why i'm getting wrong answer for this problem ?
Code: Select all
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
int t;
scanf("%d",&t);
for(int c=1;c<=t;c++){
int n;
scanf("%d",&n);
printf("Case %d:",c);
for(int i=(int)sqrt(n);i>1;i--){
if(n%i==0){
int r=n-i*i;
if(r!=0)
printf(" %d",r);
}
}
n--;
if(n==0)
printf("\n");
else if(c<t)
printf(" %d\n",n);
else
printf(" %d",n);
}
return 0;
}