码迷,mamicode.com
首页 > 其他好文 > 详细

Moduli number system

时间:2015-07-09 13:08:47      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

A number system with moduli is de?ned by a vector of k moduli, [m1,m2, ···,mk].

The moduli must be pairwise co-prime, which means that, for any pair of moduli, the only common factor is 1.

In such a system each number n is represented by a string "-x1--x2-- ... --xk-" of its residues, one for each modulus. The product m1 ... mk must be greater than the given number n which is to be converted in the moduli number system.

For example, if we use the system [2, 3, 5] the number n = 11 is represented by "-1--2--1-",
the number n = 23 by "-1--2--3-". If we use the system [8, 7, 5, 3] the number n = 187 becomes "-3--5--2--1-".

You will be given a number n (n >= 0) and a system S = [m1,m2, ···,mk] and you will return a string "-x1--x2-- ...--xk-" representing the number n in the system S.

If the moduli are not pairwise co-prime or if the product m1 ... mk is not greater than n, return "Not applicable".

Examples:

fromNb2Str(11 [2,3,5]) -> "-1--2--1-"

fromNb2Str(6, [2, 3, 4]) -> "Not applicable", since 2 and 4 are not coprime

fromNb2Str(7, [2, 3]) -> "Not applicable" since 2 * 3 < 7

fromNb2Str 187 [8,7,5,3] -> "-3--5--2--1-"
fromNb2Str 6 [2, 3, 4] -> "Not applicable", since 2 and 4 are not coprime
fromNb2Str 7 [2, 3] -> "Not applicable", since 2 * 3 < 7

 

Moduli number system

标签:

原文地址:http://www.cnblogs.com/chucklu/p/4632788.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!