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

能被8整除的特性:最后三位可以被8整除。

 #include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
using namespace std; const int SIZE = ;
char S[SIZE];
bool VIS[SIZE],FLAG;
vector<char> ANS; void dfs(int start,int sum,int count);
int main(void)
{
cin >> S;
dfs(,,);
if(!FLAG)
puts("NO"); return ;
} void dfs(int start,int sum,int count)
{
if(FLAG || count > )
return ;
for(int i = start;S[i];i ++)
{
if(FLAG)
return ;
if(!VIS[i])
{
VIS[i] = true;
int back = sum;
ANS.push_back(S[i]);
sum = ANS[ANS.size() - ] - '';
if(ANS.size() >= )
sum += (ANS[ANS.size() - ] - '') * ;
if(ANS.size() >= )
sum += (ANS[ANS.size() - ] - '') * ;
if(sum % == )
{
cout << "YES" << endl;
for(int i = ;i < ANS.size();i ++)
cout << ANS[i];
cout << endl;
FLAG = true;
return ;
} dfs(i + ,sum,count + );
VIS[i] = false;
sum = back;
ANS.pop_back();
}
}
}

Divisibility by Eight (数学)的更多相关文章

  1. cf306 C. Divisibility by Eight(数学推导)

    C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  3. Codeforces Round #829 (Div. 2) D. Factorial Divisibility(数学)

    题目链接 题目大意: \(~~\)给定n个正整数和一个数k,问这n个数的阶乘之和能不能被k的阶乘整除 既:(a\(_{1}\)!+a\(_{2}\)!+a\(_{3}\)!+....+a\(_{n}\ ...

  4. Codeforces 922.F Divisibility

    F. Divisibility time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. 数学思想:为何我们把 x²读作x平方

    要弄清楚这个问题,我们得先认识一个人.古希腊大数学家 欧多克索斯,其在整个古代仅次于阿基米德,是一位天文学家.医生.几何学家.立法家和地理学家. 为何我们把 x²读作x平方呢? 古希腊时代,越来越多的 ...

  6. 速算1/Sqrt(x)背后的数学原理

    概述 平方根倒数速算法,是用于快速计算1/Sqrt(x)的值的一种算法,在这里x需取符合IEEE 754标准格式的32位正浮点数.让我们先来看这段代码: float Q_rsqrt( float nu ...

  7. MarkDown+LaTex 数学内容编辑样例收集

    $\color{green}{MarkDown+LaTex 数学内容编辑样例收集}$ 1.大小标题的居中,大小,颜色 [例1] $\color{Blue}{一元二次方程根的分布}$ $\color{R ...

  8. 深度学习笔记——PCA原理与数学推倒详解

    PCA目的:这里举个例子,如果假设我有m个点,{x(1),...,x(m)},那么我要将它们存在我的内存中,或者要对着m个点进行一次机器学习,但是这m个点的维度太大了,如果要进行机器学习的话参数太多, ...

  9. Sql Server函数全解<二>数学函数

    阅读目录 1.绝对值函数ABS(x)和返回圆周率的函数PI() 2.平方根函数SQRT(x) 3.获取随机函数的函数RAND()和RAND(x) 4.四舍五入函数ROUND(x,y) 5.符号函数SI ...

随机推荐

  1. Lucene/ElasticSearch 学习系列 (1) 为什么学,学什么,怎么学

    为什么学 <What I wish I knew When I was 20>这本书给了我很多启发.作者在书中提到,Stanford 大学培养人才的目标是 ”T形人才“:精通某个领域,但对 ...

  2. Server-U与IIS端口占用问题解决

    在新版的ftp软件Server-U(11.X)中,由于其默认设置中监听了80端口,经常会导致IIS不能服务不能正常启用,下面记录如何修改server-u的80端口.     打开Server-U软件, ...

  3. C#生成不重复随机数的方法

    在使用Random类生成随机数时,我们可能会碰到生成随机数重复的问题. 比如我们要生成6位数字验证码,虽然也是使用Random,但是可能出现111111,999999这样的情况. 这是因为在实例化Ra ...

  4. hdu 2821 Pusher (dfs)

    把这个写出来是不是就意味着把   http://www.hacker.org/push  这个游戏打爆了? ~啊哈哈哈 其实只要找到一个就可以退出了  所以效率也不算很低的  可以直接DFS呀呀呀呀 ...

  5. 10635 - Prince and Princess

    Problem D Prince and Princess Input: Standard Input Output: Standard Output Time Limit: 3 Seconds In ...

  6. MON166 FAQ

    MON166: SOFTWARE RESET USING THE MONITOR QUESTION What happens when debugging using MON166 and my pr ...

  7. 减少远程ssh的延迟

    今天搞了个很廉价的vps,ssh上去之后操作卡顿得不行,有时候输入一行命令后需要等五六秒才显示出来,蛋疼得不行. 然后想找一个解决方案,先是看到了mosh. 搜索了下教程,看了下说明,因为我这个廉价的 ...

  8. Codeforces Round #338 (Div. 2) D. Multipliers 数论

    D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...

  9. 64位ubuntu下装32位软件

    本帖最后由 wuy069 于 2013-10-25 12:28 编辑 很多软件只有32位的,有的依赖32位库还挺严重的:从ubuntu 13.10已经废弃了ia32-libs,但可以使用多架构,安装软 ...

  10. Linux下高并发socket链接数测试

    一.如何增大service进程的max open files ulimit -n 只能改小max open files,不能改大.需要按照以下步骤: 修改/etc/security/limits.co ...