ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1024. Permutations

LCM and long long
Posted by Alexander J. Villalba G. 16 Apr 2011 06:29
the solution is achieved using LCM (MCM in Spanish) and long long to express the result
Re: LCM and long long
Posted by Alexander J. Villalba G. 16 Apr 2011 06:30
no is necesary GCD
Re: LCM and long long
Posted by Evgeniy++ 17 Jul 2011 03:09
> long long to express result

Correct! Overflow can happen otherwise.

Edited by author 17.07.2011 03:09

Edited by author 17.07.2011 03:09
Re: LCM and long long
Posted by Ignas 8 Aug 2011 22:13
The final answer fits int type. BUT when you multiply two ints, you must convert the product to long long. After that you divide the product and the answer doesn't exceed int range :)
Re: LCM and long long
Posted by Savchenkov (NNSTU) 28 Oct 2011 00:23
NO! You don't need long long!

Instead of:   a * b / gcd(a,b)
Use this:     a / gcd(a,b) * b

This way you won't get overflow.