预处理

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循环进行查找数据得出。

全部评论

相关推荐

已oc&nbsp;云智断更了好几天,也有一些话想说,继续更新一篇云智timeline&nbsp;4.18&nbsp;一面&nbsp;半个小时后约二面&nbsp;4.21二面&nbsp;当晚&nbsp;约hr面&nbsp;4.23hr面&nbsp;4.30&nbsp;发offer之前美团的二面挂了,进入人才库,后面又被捞起来面试,4.30号&nbsp;美团又一面,现在还没出一面结果感觉也不报什么希望,就算一面过了,还有二面,我经不起深入拷打,唉,真的,好难五一躺平了五天,吃吃玩玩睡睡~还要担心毕业,科研更是难,唉暑期可能就到此为止了,后面没有时间在这个上面了,要抓紧时间做科研,为了后面能出去实习。大厂,秋招再见!!!有一些感慨:4.1是我的第一次面试,美团,面试的时候紧张到浑身发...
daisy9542:我今晚也是美团一面,已经第六次了。我也面了其他的,没拿到 offer。但我想开了,要按照自己的节奏来,找暑期转正然后秋招大杀四方并不是唯一的出路,其实还有很多选择的,有 0 实习最后秋招拿 offer 了,也有不选择互联网去国企的外企的,考编的,创业的。现在的失败不代表以后的路都是黑暗的,只不过可能运气还没降临到头上。所以现在要做的,就是放平心态,提升自己,通过面试了解到自己的优点和不足,争取下次机会来了能好好抓住
点赞 评论 收藏
分享
牛客10001:问就是六个月,全国可飞,给钱就干
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务