第十六届图森未来杯题目G-Lucky 7 in the Pocket

博客围绕寻找幸运整数展开,定义能被7整除但不能被4整除的整数为幸运整数。给定整数n,需找出大于等于n的最小幸运整数m。给出了输入输出格式及示例,还提及了解法但未详细说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:
BaoBao loves number 7 but hates number 4, so he refers to an integer x as a “lucky integer” if x 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 n in his left pocket. As BaoBao dislikes large integers, he decides to find a lucky integer m such that m ≥ n and m is as small as possible. Please help BaoBao calculate the value of m.

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

The first and only line contains an integer n (1 ≤ n ≤ 100), indicating the integer in BaoBao’s left pocket.

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

Sample Input
4
1
7
20
28
Sample Output
7
7
21
35

解法:

import java.util.Scanner;

public class Main {
	public Main(int n){
		while(true){
			if(n % 7 == 0 && n % 4 != 0){
				System.out.println(n);
				break;
			}else{
				n ++;
			}
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for(int i = 0; i < m; i ++){
			int n = sc.nextInt();
			Main slove = new Main(n);
		}	
		sc.close();
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值