Page 1 of 2
10879 - Code Refactoring
Posted: Fri Oct 14, 2005 1:03 am
by mamun
Can anyone tell me what factorizing scheme is used for the code,K?
Thanks in advance!
Posted: Sat Oct 15, 2005 7:47 am
by mysword
find the first 2 prime factors
Posted: Sat Oct 15, 2005 2:58 pm
by mamun
mysword wrote:find the first 2 prime factors
Then do what? None of the sample outputs are showing anything related to first 2 primes. Am i wrong?
Posted: Sat Oct 15, 2005 3:40 pm
by mysword
any correct solutions can be accepted
no need be the same with the sample input-output
Posted: Sat Oct 15, 2005 3:44 pm
by mamun
mysword wrote:any correct solutions can be accepted
no need be the same with the sample input-output
Really? Then that should have been specified. Now I'll give a try.
Thanx!
Re: 10879 - Code Refactoring
Posted: Fri May 02, 2008 4:09 pm
by kbr_iut
Dleted after AC
Re: 10879 - Code Refactoring
Posted: Sat May 03, 2008 2:10 pm
by Jan
Check your result for 32.
Re: 10879 - Code Refactoring(I am confused!!!!)
Posted: Sat May 03, 2008 7:30 pm
by kbr_iut
actually I misunderstud something....anyway AC now...again and again thanx....
Re: 10879 - Code Refactoring why RTE
Posted: Sun Nov 30, 2008 8:15 pm
by abid_iut
why i am getting RTE for this problem. I think this is a quite easy problem and all input is also giving the output
so where is the problem
please help somebody
here is the code:
pls pls

Re: 10879 - Code Refactoring
Posted: Mon Dec 01, 2008 8:47 am
by Articuno
Hi Abid, in your code you have implemented sieve to check whether the input is a prime or not. Your sieve is upto 1,000,000. But please check the highest value for the input. When you are checking whether 10,000,000 is a prime or not..... what you think? Is'nt there a problem?
I have used your code and got accepted without doing any prime checking. Read the description of the problem carefully. There will be no prime numbers in the input. So..... You don't need to use sieve. Goodluck.
[By the way, you have used %lld for long data type which will be %ld...i think]
Re: 10879 - Code Refactoring
Posted: Mon Dec 01, 2008 9:55 am
by abid_iut
Thankx Articuno
AC at last after 11 submission
thankx for ur help
Runtime error 10879 - Code Refactoring
Posted: Fri Jan 09, 2009 2:43 pm
by xtremedreamer
I am getting run time error for this problem. As the problem is related to find prime factors. I have build an array to hold prime numbers upto 5,000,001 thinking that it is sufficient. As i have tested various inputs while it pass. So can't understand what happens to the judge.
Anybody plz help. Here is my code:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
//#include <time.h>
#include <vector>
#define N 5000002
using namespace std;
bool isprime[N];
typedef unsigned int uint;
/****Sieve Prime Generator****/
void fill(){
memset(isprime,1,sizeof(bool)*N);
for(uint i = 2; i < N; i++){
if(isprime[i])
for(uint k = (i<<1); k < N; k+=i)
isprime[k] = false;
}
}
int main(){
int i, n, Case=1, Number, count, temp;
scanf("%d",&n);
vector<int>NextPrime;
fill();
for (i = 2; i < N; i++){
if (isprime[i])
NextPrime.push_back(i);
}
vector<int>::iterator it;
while(n-- > 0){
count = 0;
scanf("%d",&Number);
printf("Case #%d: %d",Case++, Number);
temp = 0;
for (it = NextPrime.begin(); count < 2; it++){
if (!(Number%(*it)) && ((*it)*(*it)) != Number && temp != *it){
temp = Number/(*it);
printf(" = %d * %d",*it,temp);
count++;
}
}
printf("\n");
}
return 0;
}
Thanks in advance.
Re: 10879 - Code Refactoring
Posted: Sun Jan 11, 2009 7:25 am
by Obaida
NO need to produce primes.
This is an easy straight forward problem!!! just find the divisors using sqrt(n); where n is the input.
Be care full about this,
K = A * B = C * D", where A, B, C and D are different positive integers larger than 1.
Re: 10879 - Code Refactoring
Posted: Thu Nov 11, 2010 11:27 pm
by SePulTribe
Hi guys,
This is my code. I've tested it with everything and it still fails. Is it possible for you guys to help? I'm very frustrated.
Code: Select all
#include <cassert>
#include <cstdio>
#include <cmath>
using namespace std;
long long N, yy, ii, sq, K, countee, prev;
int main(void)
{
scanf("%lld\n", &N);
for (yy = 1; yy <= N; yy++)
//for (yy = 10000000; yy > 1; yy--)
{
scanf("%lld\n", &K);
//K = yy;
sq = (int)sqrt((long double)K);
printf("Case #%lld: %lld", yy, K);
countee = 0;
for (ii = 2; countee < 2 && ii < sq; ii++)
{
if (!(K % ii))
{
if (countee > 0 && (ii == prev))
continue;
printf(" = %lld * %lld", ii, (prev = K / ii));
countee++;
}
}
printf("\n");
}
return 0;
}
Re: 10879 - Code Refactoring
Posted: Wed Apr 20, 2011 3:13 pm
by wafaa
Hello .. I'm new here
i need a help
please !! I don't anderstand this problem any way
what is he want ?
thanks in advance