10879 - Code Refactoring

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

Moderator: Board moderators

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

10879 - Code Refactoring

Post by mamun » Fri Oct 14, 2005 1:03 am

Can anyone tell me what factorizing scheme is used for the code,K?
Thanks in advance!

mysword
New poster
Posts: 26
Joined: Sun Mar 06, 2005 8:52 am

Post by mysword » Sat Oct 15, 2005 7:47 am

find the first 2 prime factors

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Sat Oct 15, 2005 2:58 pm

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?

mysword
New poster
Posts: 26
Joined: Sun Mar 06, 2005 8:52 am

Post by mysword » Sat Oct 15, 2005 3:40 pm

any correct solutions can be accepted
no need be the same with the sample input-output

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Sat Oct 15, 2005 3:44 pm

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!

User avatar
kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 10879 - Code Refactoring

Post by kbr_iut » Fri May 02, 2008 4:09 pm

Dleted after AC
Last edited by kbr_iut on Wed Sep 10, 2008 10:44 am, edited 1 time in total.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10879 - Code Refactoring

Post by Jan » Sat May 03, 2008 2:10 pm

Check your result for 32.
Ami ekhono shopno dekhi...
HomePage

User avatar
kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 10879 - Code Refactoring(I am confused!!!!)

Post by kbr_iut » Sat May 03, 2008 7:30 pm

actually I misunderstud something....anyway AC now...again and again thanx....
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10879 - Code Refactoring why RTE

Post by abid_iut » Sun Nov 30, 2008 8:15 pm

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:

Code: Select all

Removed after AC
pls pls :(
Last edited by abid_iut on Mon Dec 01, 2008 9:56 am, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 10879 - Code Refactoring

Post by Articuno » Mon Dec 01, 2008 8:47 am

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]
May be tomorrow is a better day............ :)

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10879 - Code Refactoring

Post by abid_iut » Mon Dec 01, 2008 9:55 am

Thankx Articuno
AC at last after 11 submission :D
thankx for ur help
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

xtremedreamer
New poster
Posts: 5
Joined: Sun Dec 21, 2008 7:19 am

Runtime error 10879 - Code Refactoring

Post by xtremedreamer » Fri Jan 09, 2009 2:43 pm

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.

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10879 - Code Refactoring

Post by Obaida » Sun Jan 11, 2009 7:25 am

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.
try_try_try_try_&&&_try@try.com
This may be the address of success.

SePulTribe
New poster
Posts: 28
Joined: Mon Nov 15, 2004 5:00 pm

Re: 10879 - Code Refactoring

Post by SePulTribe » Thu Nov 11, 2010 11:27 pm

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

wafaa
New poster
Posts: 1
Joined: Sat Mar 12, 2011 9:35 am

Re: 10879 - Code Refactoring

Post by wafaa » Wed Apr 20, 2011 3:13 pm

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

Post Reply

Return to “Volume 108 (10800-10899)”