**C - Lucky 7 in the Pocket **

BaoBao loves number 7 but hates number 4, so he refers to an integer as a "lucky integer" if is divisible by 7 but not divisible by 4. For example, 7, 14 and 21 are lucky integers, but 1, 4 and 28 are not.

Today BaoBao has just found an integer in his left pocket. As BaoBao dislikes large integers, he decides to find a lucky integer such that and is as small as possible. Please help BaoBao calculate the value of .

Input

There are multiple test cases. The first line of the input is an integer (about 100), indicating the number of test cases. For each test case:

The first and only line contains an integer (), indicating the integer in BaoBao's left pocket.

Output

For each test case output one line containing one integer, indicating the value of .

Sample Input

4

1

7

20

28

Sample Output

7

7

21

35

正确代码

	#include <iostream>  

	using namespace std;  

	int a[1000];  

	int main(){
for (int i = 1; i < 1000; ++i) {
if(i%7==0&&i%4!=0){
a[i]=1;
}
}
int T;
cin>>T;
while (T--){
int n;
cin>>n;
for (int i = n; i < 1000; ++i) {
if(a[i]==1){
cout<<i<<endl;
break;
}
}
}
return 0;
}

题意理解

首先,题意规定了n的取值范围,因为取值范围足够小,仅仅在1-100之间,因此我选择使用预处理即计算1-1000之内所有可以被7整除而不能被4整除的数,接着用for循环进行查找数据得出。

#C++初学记录(acm试题#预处理)的更多相关文章

  1. #C++初学记录(ACM试题2)

    Max Sum Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-seq ...

  2. #C++初学记录(ACM试题1)

    A - Diverse Strings A string is called diverse if it contains consecutive (adjacent) letters of the ...

  3. #C++初学记录ACM补题(D. Candies!)前缀和运算。

    D - Candies!   Consider a sequence of digits of length [a1,a2,-,a]. We perform the following operati ...

  4. #C++初学记录(set进阶#acm cf 190802 B. Subsegments)

    B. Subsegments#set进阶 Programmer Sasha has recently begun to study data structures. His coach Stas to ...

  5. #C++初学记录(sort函数)

    sort函数 前言:当进行贪心算法的学习时,需要用到sort函数,因为初学c++汇编语言,sort的具体用法没有深入学习,所以这里进行sort学习记录并只有基础用法并借用贪心算法题目的代码. 百度百科 ...

  6. 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始

    以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告

  7. javaweb初学记录

    原文 链接 http://blog.csdn.net/iojust/article/details/52429805 - ---热情依旧 - 环境搭建: - jdk环境配置 jdk下载: http:/ ...

  8. #C++初学记录(算法4)

    A - Serval and Bus It is raining heavily. But this is the first day for Serval, who just became 3 ye ...

  9. 北大ACM试题分类+部分解题报告链接

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

随机推荐

  1. SAP Marketing Cloud功能简述(五) : 销售计划管理

    Grace前四篇介绍SAP Marketing Cloud的文章: SAP Marketing Cloud功能简述(一) : Contacts和Profiles SAP Marketing Cloud ...

  2. Android查看应用方法数

    当一个项目快速迭代时,难免引进各种依赖,从而导致单个apk超过65k的限制.如何查询apk的方法数也是每个Android Developer必备技能. 我使用的是 dex-method-counts  ...

  3. vscode编辑器中文乱码问题

    设置配置自动格式化: "[javascriptreact]": { "editor.defaultFormatter": "esbenp.pretti ...

  4. java23种设计模式专攻:生产者-消费者模式的三种实现方式

    公司的架构用到了dubbo.带我那小哥也是个半吊子,顺便就考我生产者消费者模式,顺便还考我23种java设计模式,

  5. p2.BTC-数据结构

    hash pointers:哈希指针,除了保存值的地址,还要存这整个区块的内容的hash值.这样就既能访问到值,还能确定访问的值有没有被篡改. 一 Blockchain Block chain is ...

  6. Ceph FS 挂载

    Cephfs使用挂载方式有两种 1.使用linux kernel挂载 mount 2.使用ceph-fuse挂载. 1.下图为mount挂载 mount -t ceph 10.110.180.112: ...

  7. Linux学习django-CentOS部署自己本地的django项目

    前言 自己本地写好的django项目,如何部署到linux服务器上,让其他的小伙伴也能访问呢?本篇以centos系统为例,把本地写好的django项目部署到linux服务器上环境准备: 环境准备:1. ...

  8. 在openwrt上使用autossh(已放弃)

    用了一天后发现,这东西真不靠谱,还不如自已写的SHELL检测重连来的精准和方便,放弃中 参考文章: https://my.oschina.net/umu618/blog/849345 https:// ...

  9. Type mismatch: cannot convert from element type Object to String 解决办法

    首先放上我的源码,看看你的代码是不是我这个类似的. @Test void predicateTest() throws Exception { List<String> languages ...

  10. Vuex状态管理总结

    一.什么是 Vuex 1.Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式 2.Vuex 采用集中式存储和管理应用中所有组件的状态 3.Vuex 应用的核心是 store(仓库)-- 包 ...