1 / 3

10212 : The Last Non-zero Digit

10212 : The Last Non-zero Digit. ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10212 : The Last Non-zero Digit 解題者: 陳秉躍 解題日期: 20 14 年 5 月 22 日 題意: 給 你 2 個整數 N 、 M , N 個不同的東西找出 M 個東西排列不同的方式,印出最後一個不為 0 的數字。 N ( 0 <= N <= 2 * 10 7 ) , M ( 0 <= M <= N ).

Download Presentation

10212 : The Last Non-zero Digit

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 10212 : The Last Non-zero Digit • ★★★☆☆ • 題組:Problem Set Archive with Online Judge • 題號:10212 : The Last Non-zero Digit • 解題者:陳秉躍 • 解題日期:2014年5月22日 • 題意:給你2個整數N、M,N個不同的東西找出M個東西排列不同的方式,印出最後一個不為0的數字。N(0 <= N <= 2*107),M(0 <= M <= N)

  2. 題意範例:10 10 81055256 2 • 解法:M> 0 : ( N * (N - 1) * (N - 2) … (N - M+1 ) )%10M = 0 : 1%10可是因為N最大等於2*107 =>大數運算 ?只需要long longint,因為題目只要求印出最後一個不為0的數字每次乘法計算後的結果1. 個位數字為0,就除以10,直到個位數字不為02.mod 1010最後 mod 10 以後 印出來

  3. 解法範例:106 10 * 9 * 8 * 7 * 6 * 510 * 9=90 => 99 * 8=72 => 7272 * 7=504 => 504504 * 6=3024 => 30243024 * 5=15120 => 1512ans = 2 • 討論:

More Related