數(shù)字運(yùn)算,判斷一個(gè)數(shù)是否接近素?cái)?shù)
A Niven number is a number such that the sum of its digits divides itself. For example, 111 is a Niven number because the sum of its digits is 3, which divides 111. We can also specify a number in another base b, and a number in base b is a Niven number if the sum of its digits divides its value.
Given b (2 <= b <= 10) and a number in base b, determine whether it is a Niven number or not.
Input
Each line of input contains the base b, followed by a string of digits representing a positive integer in that base. There are no leading zeroes. The input is terminated by a line consisting of 0 alone.
Output
For each case, print "yes" on a line if the given number is a Niven number, and "no" otherwise.
Sample Input
10 111
2 110
10 123
6 1000
8 2314
0
Sample Output
yes
yes
no
yes
no
The government of a small but important country has decided that the alphabet needs to be streamlined and reordered. Uppercase letters will be eliminated. They will issue a royal decree in the form of a String of B and A characters. The first character in the decree specifies whether a must come ( B )Before b in the new alphabet or ( A )After b . The second character determines the relative placement of b and c , etc. So, for example, "BAA" means that a must come Before b , b must come After c , and c must come After d .
Any letters beyond these requirements are to be excluded, so if the decree specifies k comparisons then the new alphabet will contain the first k+1 lowercase letters of the current alphabet.
Create a class Alphabet that contains the method choices that takes the decree as input and returns the number of possible new alphabets that conform to the decree. If more than 1,000,000,000 are possible, return -1.
Definition
使用到的參數(shù)跟談到彈性網(wǎng)絡(luò)的那一章里頭所講的是一樣的, ke 則是終止條件。如果 step 被打勾,則程式在每一步之間會(huì)暫停 100毫秒(或其他使用者輸入的數(shù)值)。如果 Random 被打勾,則程式會(huì)以系統(tǒng)時(shí)間作為亂數(shù)產(chǎn)生器的種子數(shù),否則,就以使用者輸入的數(shù)( Random 右邊那一格)為種子數(shù)。
你可以利用 load 來載入推銷員問題檔與其最佳解,如此便可比較彈性網(wǎng)絡(luò)所找出來的解與最佳解差了多少。
Central, Radius, and Error 這三個(gè)參數(shù)的前兩個(gè),只影響彈性網(wǎng)絡(luò)的起使位置和大小,對求解沒有影響。第三個(gè)參數(shù)代表城市與網(wǎng)絡(luò)點(diǎn)之間的容忍距離,也就是說,如果某城市與某網(wǎng)絡(luò)點(diǎn)之間的距離,小于容忍距離,那就把這個(gè)城市當(dāng)成是被該網(wǎng)絡(luò)點(diǎn)所拜訪。
按下小 w按鈕會(huì)將目前的結(jié)果與參數(shù)值寫到“en.out”這個(gè)檔案。使得我們可以很方便地來比較不同參數(shù)的效果。
We have a group of N items (represented by integers from 1 to N), and we know that there is some total order defined for these items. You may assume that no two elements will be equal (for all a, b: a<b or b<a). However, it is expensive to compare two items. Your task is to make a number of comparisons, and then output the sorted order. The cost of determining if a < b is given by the bth integer of element a of costs (space delimited), which is the same as the ath integer of element b. Naturally, you will be judged on the total cost of the comparisons you make before outputting the sorted order. If your order is incorrect, you will receive a 0. Otherwise, your score will be opt/cost, where opt is the best cost anyone has achieved and cost is the total cost of the comparisons you make (so your score for a test case will be between 0 and 1). Your score for the problem will simply be the sum of your scores for the individual test cases.