C. Divisibility by Eight
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.

Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.

If a solution exists, you should print it.

Input

The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.

Output

Print "NO" (without quotes), if there is no such way to remove some digits from number n.

Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.

If there are multiple possible answers, you may print any of them.

Sample test(s)
input
3454
output
YES
344
input
10
output
YES
0
input
111111
output
NO

解题思路:

可被2整除 : 偶數。
可被3整除 : 各位數字之和能被3整除。
可被4整除 : 最末兩位數字所成的2位數能被4整除。
可被5整除 : 末位為 0 或 5。
可被6整除 : 同時滿足被2和3整除的條件。

可被7整除 : 
設一數為 abc def , 則 def - abc 能被7整除 ,
又如 abc def ghi , 則 ghi - def + abc 能被7整除 ,
再如 abc def ghi jkl , 則 jkl - ghi + def - abc 能被7整除, 如此類推。
以上任何字母包括首位可為0 , 此法亦適合判別能否被11或13整除。

可被8整除 : 最末三位數字所成的3位數能被8整除。
可被9整除 : 各位數字之和能被9整除。
可被10整除 :  末位為 0。
可被11整除 :  奇位數字和 -  偶位數字和能被11整除。
可被12整除 :  同時滿足被3和4整除的條件。
可被13整除 :  (同可被7整除之法則)

cf306 C. Divisibility by Eight(数学推导)的更多相关文章

  1. 借One-Class-SVM回顾SMO在SVM中的数学推导--记录毕业论文5

    上篇记录了一些决策树算法,这篇是借OC-SVM填回SMO在SVM中的数学推导这个坑. 参考文献: http://research.microsoft.com/pubs/69644/tr-98-14.p ...

  2. 关于不同进制数之间转换的数学推导【Written By KillerLegend】

    关于不同进制数之间转换的数学推导 涉及范围:正整数范围内二进制(Binary),八进制(Octonary),十进制(Decimal),十六进制(hexadecimal)之间的转换 数的进制有多种,比如 ...

  3. UVA - 10014 - Simple calculations (经典的数学推导题!!)

    UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...

  4. 『sumdiv 数学推导 分治』

    sumdiv(POJ 1845) Description 给定两个自然数A和B,S为A^B的所有正整数约数和,编程输出S mod 9901的结果. Input Format 只有一行,两个用空格隔开的 ...

  5. LDA-线性判别分析(二)Two-classes 情形的数学推导

    本来是要调研 Latent Dirichlet Allocation 的那个 LDA 的, 没想到查到很多关于 Linear Discriminant Analysis 这个 LDA 的资料.初步看了 ...

  6. leetcode 343. Integer Break(dp或数学推导)

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  7. [hdu5307] He is Flying [FFT+数学推导]

    题面 传送门 思路 看到这道题,我的第一想法是前缀和瞎搞,说不定能$O\left(n\right)$? 事实证明我的确是瞎扯...... 题目中的提示 这道题的数据中告诉了我们: $sum\left( ...

  8. ZOJ3329(数学推导+期望递推)

    要点: 1.期望的套路,要求n以上的期望,则设dp[i]为i分距离终点的期望步数,则终点dp值为0,答案是dp[0]. 2.此题主要在于数学推导,一方面是要写出dp[i] = 什么,虽然一大串但是思维 ...

  9. [国家集训队]整数的lqp拆分 数学推导 打表找规律

    题解: 考场上靠打表找规律切的题,不过严谨的数学推导才是本题精妙所在:求:$\sum\prod_{i=1}^{m}F_{a{i}}$ 设 $f(i)$ 为 $N=i$ 时的答案,$F_{i}$ 为斐波 ...

随机推荐

  1. POJ 1659 Frogs' Neighborhood(Havel-Hakimi定理)

    题目链接: 传送门 Frogs' Neighborhood Time Limit: 5000MS     Memory Limit: 10000K Description 未名湖附近共有N个大小湖泊L ...

  2. django 模板中url的处理

    在模板中直接添加‘/home’这样的链接是十分不推荐的,因为这是一个相对的链接,在不同网页中打开可能会返回不一样的结果. 所以推荐的是 <a href="{{ object.get_a ...

  3. Form Submit表单提交

    <button type="button" ng-click="submit()"class="btn btn-block btn-danger ...

  4. 什么是linux的ftp

    vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小巧轻快,安全易用.并且是一个完全免费开放源码的ftp软件ftp的作用: FTP(File Transfer Protocol, ...

  5. Apple Instruments

    启动Xcode,选择Xcode > Open Developer Tool > Instruments. 如果无法选择当前设备,请尝试重启设备. 将设备设置为Use for develop ...

  6. ecshop 默认图处理

    function get_banner_path($img) { $img = empty($img) ? C('no_picture') : $img; return $img;}

  7. UITextView限制输入文字

    一.设置UITextView的delegate为控制器 二.实现代理方法 #pragma mark - UITextViewDelegate - (BOOL)textView:(UITextView ...

  8. python 函数基础介绍

    函数是对程序逻辑进行结构化或过程化的一种编程方法.能将整块代码巧妙地隔离成易于管理的小块,把重复代码放在函数中而不是进行大量的拷贝. 一.函数创建 def 函数创建格式如下: def function ...

  9. Create new tool for CSV

    CsvFileStream.cs public class CsvFileStream { TextReader stream; bool EOS = false; bool EOL = false; ...

  10. NestIn VS插件 visual studio 中将同类CS文件放在一起显示

    https://visualstudiogallery.msdn.microsoft.com/9d6ef0ce-2bef-4a82-9a84-7718caa5bb45 Nest files in So ...