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 ...
随机推荐
- make and make bzImage
2.6内核 make = make bzImage + make modules 无非是改下Makefile而已 2.4 内核 01.make menuconfig 02.make dep 03.ma ...
- Detecting Underlying Linux Distro
If you are the owner of the system, then you know which Linux is installed and running. This article ...
- CentOS7部署Nginx
CentOS7部署Nginx 1.准备工作 Nginx的安装依赖于以下三个包,意思就是在安装Nginx之前首先必须安装一下的三个包,注意安装顺序如下: 1 SSL功能需要openssl库,直接通过yu ...
- Oracle WIHT AS 用法
1.with table as 相当于建个临时表(用于一个语句中某些中间结果放在临时表空间的SQL语句),Oracle 9i 新增WITH语法,可以将查询中的子查询命名,放到SELECT语句的最前面. ...
- dwz 刷新当前navtab
List.jsp 其navtabId为TradingStrategy_31: <form method="post" action="${contextPath}/ ...
- Jetty学习二:配置概览-怎么配置Jetty
Jetty POJO配置 Jetty的核心组件是Plain Old Java Objects(POJOs):配置Jetty的大部分工作就是在Jetty POJOs上的初始化.装配和设置域的处理,你能通 ...
- [Linux] 关于Unix哲学
reference : http://www.ruanyifeng.com/blog/2009/06/unix_philosophy.html 先讲两个很老的小故事. 第一个故事. 有一家日本最大的化 ...
- java读取文件并获得文件编码,转换为指定编码的工具类代码
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...
- Java---多线程断点下载
在上一章中我们实现了多线程下载功能,这里我们添加断点下载功能,防止下载过程中程序意外退出.具体代码如下: package com.jwzhangjie; /** * 说明: * 每一个线程下载的位置计 ...
- javascript基础知识梳理-Number与String之间的互相转换【转】
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...