Divisibility by Eight
把当前数删除几位然后能够整除与8
那么可得知大于3位数的推断能否整除于八的条件是(n%1000)%8==0
能够得出我们的结论:仅仅须要枚举后三位后两位后一位就可以知道是否可整除于8
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char a[200];
int main() {
//printf("%d\n",344%8);
int ans = 0 ;
int flag = 0;
scanf("%s",a);
int l = strlen(a);
if(l>=3) {
for(int i=0; i<l-2; ++i) {
if(a[i]=='0') continue;
for(int j=i+1; j<l-1; ++j) {
for(int k=j+1; k<l; ++k) {
ans = (a[i]-'0')*100+(a[j]-'0')*10+a[k]-'0';
if(ans%8==0){
flag=1;
break;
}
}
if(flag) break;
}
if(flag)break;
}
}
// printf(" %d %d\n",flag,ans);
if(!flag&&l>=2) {
for(int i=0; i<l-1; ++i) {
if(a[i]=='0') continue;
for(int j=i+1; j<l; ++j) {
ans = (a[i]-'0')*10+(a[j]-'0');
if(ans%8==0) {
flag=1;
break;
}
}
if(flag) break;
}
}
if(!flag) {
for(int i=0; i<l; ++i)
if((a[i]-'0')%8==0) {
ans=a[i]-'0';
flag=1;
break;
}
}
if(!flag) {
puts("NO");
} else puts("YES"),printf("%d\n",ans);
}
Divisibility by Eight的更多相关文章
- cf306 C. Divisibility by Eight(数学推导)
C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏
Clique in the Divisibility Graph time limit per test1 second memory limit per test256 megabytes inpu ...
- Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Divisibility by Eight (数学)
Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- codeforces 630J Divisibility
J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Divisibility
Description Consider an arbitrary sequence of integers. One can place + or - operators between integ ...
- HDU 3335 Divisibility (DLX)
Divisibility Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- light oj 1078 - Integer Divisibility
1078 - Integer Divisibility PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
- POJ 1745 Divisibility (线性dp)
Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10598 Accepted: 3787 Des ...
随机推荐
- USB Mass Storage communication with PassThrough / more than 64K data length
http://social.msdn.microsoft.com/Forums/windowsdesktop/zh-CN/35620a05-43be-46a8-8cbe-846bc8295d85/us ...
- IP配制
http://blog.csdn.net/laoyiin/article/details/5722977
- PyQt5 布局
import sys from PyQt5.QtWidgets import QWidget, QLabel, QApplication, QVBoxLayout, QHBoxLayout, QPus ...
- 如何使用C#关键字const,readonly,static
如果有一个值不太会变化,我们经常使用const和readonly,这2者有何不同呢?有时候,我们也会在readonly之前加上关键字static,这又意味着什么呢? const ● const默认是静 ...
- nginx简单代理配置
原文:https://my.oschina.net/wangnian/blog/791294 前言 Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器, ...
- 使用sun.misc.BASE64Decoder出错解决方案
Access restriction: The type BASE64Decoder is not accessible due to restriction on required library ...
- Oracle 10g AND Oracle 11g手工建库案例--Oracle 10g
Oracle 10g AND Oracle 11g手工建库案例--Oracle 10g 系统环境: 操作系统: RedHat EL6 Oracle: Oracle 10g and Oracle 11 ...
- noise_process.c
#include <math.h>#include "otdr_const.h"#include "haar.h"#include "ot ...
- 【转载】如果快速开发APP&创业
先贴原文所在个人博客: http://uikoo9.com/ 今天看了一些这个人的文章,还是有一定见解的,比如下面这篇 <如何快速开发出一个高质量的APP——创业谈> http://uik ...
- 第十六章 springboot + OKhttp + String.format
模拟浏览器向服务器发送请求四种方式: jdk原生的Http包下的一些类 httpclient(比较原始,不怎么用了):第一章 HttpClient的使用 Okhttp(好用,推荐) retrofit( ...