CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Product of divisors

Product of divisors

Problem code: D1

  • Submit
  • All Submissions

All submissions for this problem are available.

A tutorial for this problem is available here

Being in love with number theory, Johnny decided to take a number theory course. On the first day, he was challenged by his teacher with the following problem: given a number N, compute the product of its positive divisors. Johnny is desperate to impress his new teacher so he asks you for help.

In this problem, the divisors of N do not include the number N itself. For example, if N=12, the divisors of N (excluding N) are 1, 2, 3, 4, and 6. Thus, the product of divisors is 1x2x3x4x6=144. Since the result may be very large, if the result has more than 4 decimal digits, Johnny only needs to compute the last 4 digits of it.

Input

The first line contains t, the number of test cases (about 300,000). Then t test cases follow.

Each test case contains a single integer N (1<=N<=500,000) whose product of divisors needs to be computed.

Output

For each test case, print a single line containing the corresponding result of that test case.

Example

Input
6
3
4
12
25
957
10000

Output
1
2
144
5
7493
0000


Author: admin
Date Added: 5-05-2009
Time Limit: 2 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

admin 2 @ 15 Jun 2009 12:22 AM

You can now submit your solutions here: http://www.codechef.com/problems/D1/

utkarsh_singh @ 24 Jun 2009 05:15 AM

whenever i download the solutions written by others in C given in the right hand corner it never runs in the turbo c compiler. it always fails to run and shows general protection exception. how this programs are correct when they dont run ( very sorry to doubt the genuis of the coders behind these programs ). please can someone tell me how to make them run.

leppyr64 @ 24 Jun 2009 05:28 AM

CodeChef uses the gcc compiler.

harshvardhan @ 17 Aug 2009 08:08 PM

Why such large number of test cases and values of numbers are given as MAX limit?

admin 2 @ 17 Aug 2009 08:32 PM

@harshvardhan To make the problem interesting :)

harshvardhan @ 17 Aug 2009 11:19 PM

The problem example illustrates the product of divisors of 957 to be 7493. But i am running my code for N=957 and the list of divisors I am getting is 1,3,11, 29, 33, 87, 319 and product of divisors is 876467493.

harshvardhan @ 17 Aug 2009 11:20 PM

should the output also contain at maximum, the last 4 digits?

admin 2 @ 17 Aug 2009 11:22 PM

Read the problem statement carefully. You have to print only the last 4 digits of the product.

harshvardhan @ 17 Aug 2009 11:25 PM

ok....i got it. the result should be computed to last 4 digits. but suppose if the input data itself contains more than 4 digits, then should computation be performed over the divisors of last four digits of that number or the entire number? like.. if N=34536, then computation should be done on divisors of 34536 or 4536?

admin 2 @ 17 Aug 2009 11:28 PM

For the divisors of the entire number.

What will be the input? will

Naman Joshi @ 16 Sep 2009 10:58 PM
What will be the input? will it be a file? if it will be a file, then what type of file? a txt file or something else?

You have to read the input

admin @ 17 Sep 2009 01:58 PM
You have to read the input from stdin and output it to stdout.

what other than dividing by

rampage @ 5 Oct 2009 06:53 PM

what other than dividing by zero can cause a divide error?

and what is a NZEC error?

Please read the FAQ

admin @ 5 Oct 2009 09:36 PM

Please read the FAQ

can you pls take a look at

rampage @ 5 Oct 2009 10:33 PM

can you pls take a look at solution no. 103733.

i have tried for a long time now but can't find the error.

pls. take a look at it.

waiting for a reply

I don't like to read through

bezgin @ 19 Oct 2009 10:16 AM

I don't like to read through other people's codes. I've got the "right idea" about this problem but however I try, I can't beat the time limit. Mine takes 5 sec on my computer.

Can someone give me a link to the right algorithm?

It is linked to from the top

triplem @ 19 Oct 2009 10:21 AM

It is linked to from the top of the problem statement :P

admins can you manually check

bezgin @ 23 Oct 2009 06:46 AM

admins can you manually check out the last codes I sent? I'm running the same input that contains all the numbers from 1 to 500000 for both mine and the accepted solutions and i get the same result. (i check it with diff) And i use the same compiler like you guys.

With an input of 500000 it

triplem @ 23 Oct 2009 09:42 AM

With an input of 500000 it seems you will work with numDivisors[500000] which is outside the array bounds and can have unexpected results, so that will definitely cause wrong answer. May be other issues, but worth fixing that first.

I fixed that already, doesnt

bezgin @ 23 Oct 2009 10:53 AM

I fixed that already, doesnt seem to work anyways, but thx for replying.

Solution:131437-When

code123 @ 12 Nov 2009 07:07 PM
Solution:131437-When executing the code in my system using VS2005, the time taken for execution is zero seconds but when the same codes is uploaded in codechef it’s displaying “time limit exceeded”. Could you please tell what could be the possible reason. Also, What tool are using for compiling the programs.

Please read the FAQ and the

admin @ 12 Nov 2009 07:10 PM

Please read the FAQ and the wiki at www.codechef.com/wiki

@admin I am trying to submit

rohitmanglik @ 14 Jan 2010 11:13 PM

@admin I am trying to submit my solution in php. Can you please tell me how I can optimize my code.  Can I post my code here?

I submitted solutions for some other problems which takes a lot of memory for php in comparison to c. for same algo, I also had the timeout error for the same code of C/C++/Jave (Successfully compiled programs) written by some1 else when I change the syntax to PHP

@Rohit: PHP is slow, and it

jcomeau_ictx @ 21 Jan 2010 08:14 AM

@Rohit: PHP is slow, and it seems the online judge doesn't give it any allowance for that as it does for Python and Java. you might want to consider using another scripting language. read the FAQ about posting code; you can post a link to your submission.

@bezgin: here's an idea,

jcomeau_ictx @ 21 Jan 2010 01:30 PM

@bezgin: here's an idea, based on my experiences with this problem: if your program is expecting a single Unix-style newline char at the end of each line, that could be the cause of the "Wrong Answer". after fixing that, my program is still too slow, so can't be sure that's the only bug on my end.

finally wrote a little test program to see which testcase files have DOS-style newlines, and put #ifdef ONLINE_JUDGE conditionals to take care of the extra getchar(), so my programs don't have to check at runtime.

@Rohit, my bad, rereading the

jcomeau_ictx @ 21 Jan 2010 01:38 PM

@Rohit, my bad, rereading the FAQ says PHP is allowed 3 times the time limit. google 'php profiler' for some suggestions on how to determine the best way to speedup your code.

and what answer do you expect

shaurya @ 22 Jan 2010 01:39 AM

and what answer do you expect for input of 1

@Shaurya: the judge expects a

jcomeau_ictx @ 22 Jan 2010 03:40 AM

@Shaurya: the judge expects a "1" for "1". verified with Neelotpal's program.

@John Comeau thanks a lot....

rohitmanglik @ 1 Feb 2010 02:33 PM
@John Comeau thanks a lot.... but i think PHP has normal time limit... can u check my code n tell a better solution........( plz gimme ur id so i can mail u)

@Rohit: I haven't had a

jcomeau_ictx @ 15 Feb 2010 06:16 AM

@Rohit: I haven't had a successful entry myself yet! And in any case I won't help in that way. I believe in giving guidance where I can, but that doesn't extend to debugging or optimizing other people's programs.

my code is working just fine

tlgylmz @ 2 Mar 2010 03:28 AM

my code is working just fine with  small numbers.However when they get bigger like 10000, the product of the divisors becomes 10000^(12)/100 which my computer cannot compute. Please consider me as a noob. It's said that computing last 4 digits would be enough,but i can just compute the whole value itself with my code,which goes beyond the limits.

Any suggestions,please...

You cannot (at least, should

triplem @ 2 Mar 2010 05:42 AM

You cannot (at least, should not) solve this problem by calculating the exact value of the product of divisors and then printing out the last 4 digits. Google for modular arithmetic.

Then it's gonna be harder for

tlgylmz @ 2 Mar 2010 09:58 PM

Then it's gonna be harder for me:) Thank you.

What will be out put for

anisoftcorporation @ 21 Apr 2010 01:58 PM

What will be out put for input 500000 or greater?

@Admin : What will be out put

anisoftcorporation @ 21 Apr 2010 02:03 PM

@Admin : What will be out put for input 500000 or greater?I meant what will be the outcome in case of inpout is maximum limit or more?

The problem statement says

triplem @ 21 Apr 2010 03:06 PM

The problem statement says the input won't be larger than 500000.

i dont know ....... my

AnoopNarang @ 14 Jun 2010 04:35 AM

i dont know ....... my program is giving result of 500000 without consuming a millisecond... and here i am getting TLE.. :(

some check solution of

AnoopNarang @ 14 Jun 2010 04:41 AM

some check solution of neelotpal dhar ...... lol its damn so BIG.. 387 lines... lmao

it seems as if a simple

Rohithsreeragam @ 31 Jul 2010 04:48 PM

it seems as if a simple problem but its really terrrrible!

before attempting the problem i thought it would be easy..hats off to ones who have solved these.........................

 

anyway giving up tehse challenges would be a great loss.......

mine program too gives result

Rohithsreeragam @ 2 Aug 2010 05:53 PM

mine program too gives result ,but TLE makes a lot of trouble.............................can anyone suggest how to reduce time limit?

i am not able to post my

amayank @ 18 Sep 2010 09:07 PM

i am not able to post my solution

the submit button doesn't redirect to the proper page

please see

still the submit button is

amayank @ 18 Sep 2010 09:44 PM

still the submit button is not steady

it sometimes shows the page and many times doesnt

please correct it quickly

I am getting TLE. Following

masud040201 @ 18 Sep 2010 09:57 PM

I am getting TLE. Following is the code.

long get_me_product(long num)
{
long sprod=1;
long prod=1;
for(long i=2;i*i<=num;i++)
{
if(num%i==0)
{   
long j=num/i;
if(i!=j)
prod=((prod%10000)*(i%10000)*(j%10000))%10000;
else
prod=((prod%10000)*(i%10000))%10000;
}
}

return prod;

}

How can I optimize this code to bypass TLE? Any help will be appreciated

r = input() yy = [] for x in

abhimanyu1401 @ 10 Aug 2011 12:26 PM
r = input() yy = [] for x in range(0,r): n = input() prod = 1 k=1 while k!=n: if prod>10000: prod = prod%10000 if n%k==0: prod=prod*k k=k+1 yy.append(prod) for x in range(0,r): print yy[x], What is the error?

#include #include int

codernami @ 17 Apr 2012 01:11 PM
#include #include int main() { int flag=0; unsigned long int mul; long int tc, n ,i; printf("testcases"); scanf("%ld",&tc); while(tc--) { printf("enter no."); scanf("%ld",&n); mul=1; for(i=1;i<=(n/2);i++) { if(n%i==0) { mul=mul*i; } flag=1; } if(mul>9999) { mul=mul%10000; } if(flag==1) { printf("%lu",mul); } } getch(); return 0; } its saying time limit exceeded plzz help me to correct the above code..

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com