11466 - Largest Prime Divisor

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

Moderator: Board moderators

Re: 11466 - Largest Prime Divisor

Postby roger12345 » Thu Jun 16, 2011 7:45 pm

Help me please im gettins time limit, the input 99999999999997 doesnt finish :S

Code: Select all
AC NOW


EDIT: My sieve was too slow
roger12345
New poster
 
Posts: 3
Joined: Tue Feb 01, 2011 5:40 am

Re: 11466 - Largest Prime Divisor

Postby shaon_cse_cu08 » Tue Nov 08, 2011 7:52 pm

I use my own prime factorization function... this is Child's math... divide a number a number until it can't be divided... dan increment it by 2..bcoz all primes except for 2 are odd... and my code gave me 0.032 s... It would b more faster if i use only da prime... but sometimes Simplicity is more fun dan complexity :D
Code: Select all
#include<stdio.h>
int main()
{
   int i,n;

   while(scanf("%d",&n)!=EOF)
   {
      while(n%2==0)
      {
         printf("2 ");
         n/=2;
      }
   
      for(i=3;i*i<=n;)
      {
          if(n%i==0)
         {
            n=n/i;
            printf("%d ",i);
         }
         else
            i+=2;
      }
      if(n>1)
         printf("%d\n",n);
   }
return 0;
}
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x
User avatar
shaon_cse_cu08
New poster
 
Posts: 50
Joined: Tue May 25, 2010 9:10 am

Re: 11466 - Largest Prime Divisor

Postby PromeNabid » Sat Jun 30, 2012 1:02 am

Some sample I/O for this problem.
Input:
Code: Select all
1
-1
1111111111111
12345678910121
12345678910121
1234567891012
99999999999997
0

Output:
Code: Select all
-1
-1
265371653
173882801551
173882801551
4281283
119189511323
PromeNabid
New poster
 
Posts: 13
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.

Re: 11466 - Largest Prime Divisor

Postby masri77 » Wed Jul 18, 2012 3:35 am

The program generates correct output but gets WA please help ..

Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {
   long long int num, ans;
   long long int i;

   while (scanf("%lld", &num) && num != 0) {
      if (num < 0)
         num *= -1;

      ans = num;

      while (ans % 2 == 0)
         ans /= 2;

      i = 3;
      while (i * i <= ans) {
         if (ans % i == 0)
            ans /= i;
         else
            i += 2;
      }
      printf("%lld\n", num == ans ? -1 : ans);
   }
   return 0;
}
masri77
New poster
 
Posts: 1
Joined: Wed Jul 18, 2012 3:32 am

Re: 11466 - Largest Prime Divisor

Postby brianfry713 » Thu Jul 19, 2012 3:08 am

Doesn't match the sample I/O.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11466 - Largest Prime Divisor

Postby মেহেদী সবুজ » Mon Oct 08, 2012 1:25 pm

Code: Select all
Remove After Accepted
মেহেদী সবুজ
New poster
 
Posts: 6
Joined: Tue Apr 03, 2012 2:34 pm

Re: 11466 - Largest Prime Divisor

Postby alimbubt » Mon Apr 08, 2013 4:19 am

For this problem, Some important notes are...
1) What will happen when there exists less than 2 prime divisors.
2) What will happen when the input is less than 0.

Some Input-Output:
Input:
Code: Select all
1000
20
32
1
-1
-10
61536575712
8172385155
90090
12
199900
-26356
-32
8748234
23462482
23457826407
234872648001
436598
345387
2347
17
37
0

Output:
Code: Select all
5
5
-1
-1
-1
5
324889
16509869
13
3
1999
599
-1
113
690073
77418569
348559
521
16447
-1
-1
-1
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/
alimbubt
New poster
 
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh

Previous

Return to Volume CXIV

Who is online

Users browsing this forum: No registered users and 1 guest