11970 - Lucky Numbers

All about problems in Volume 119. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
truewt
New poster
Posts: 6
Joined: Thu Apr 14, 2011 9:34 am

11970 - Lucky Numbers

Post by truewt »

Code: Select all

 AC using suggested methods :D
Can anybody help??? My code is TLE sadly.. Is there any tricks to the search space?
Last edited by truewt on Sun Apr 17, 2011 9:42 am, edited 1 time in total.
asif_iut
New poster
Posts: 16
Joined: Mon Nov 01, 2010 8:08 am

Re: 11970 - Lucky Numbers

Post 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
iriz7482
New poster
Posts: 15
Joined: Mon Apr 04, 2011 3:18 pm

Re: 11970 - Lucky Numbers

Post 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 :D
for example, there are 2 divisors of 16 in the range [1,4) so output 2 numbers :D
Moreover, I didn't use long long and long double, long is enough :D and your code is much more complex than mine :o
truewt
New poster
Posts: 6
Joined: Thu Apr 14, 2011 9:34 am

Re: 11970 - Lucky Numbers

Post by truewt »

Thanks folks for such quick response! Managed to get AC after some thinking using iriz7482 method :P
blckhrt
New poster
Posts: 2
Joined: Wed May 04, 2011 8:25 pm
Location: Chittagong
Contact:

Re: 11970 - Lucky Numbers

Post 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;
}
kalochita
New poster
Posts: 1
Joined: Thu May 19, 2011 10:02 pm

Re: 11970 - Lucky Numbers

Post 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.
robot
New poster
Posts: 29
Joined: Sun May 24, 2009 8:39 pm

Re: 11970 - Lucky Numbers

Post 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) :)
Maqsud
New poster
Posts: 1
Joined: Thu May 28, 2015 10:16 pm

Re: 11970 - Lucky Numbers

Post 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;
}
Post Reply

Return to “Volume 119 (11900-11999)”