F 数字方格

如上图,有3个方格,每个方格里面都有一个整数a1,a2,a3。已知0 <= a1, a2, a3 <= n,而且a1 + a2是2的倍数,a2 + a3是3的倍数, a1 + a2 + a3是5的倍数。你的任务是找到一组a1,a2,a3,使得a1 + a2 + a3最大。

Input 一行,包含一个整数n (0 <= n <= 100)。

Output 一个整数,即a1 + a2 + a3的最大值。

Sample Input 3

Sample Output 5

import java.util.Scanner;

/**
 * Created by Fant.J.
 * 2017/12/5 17:30
 */
public class Main {
    public static void main(String []args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int result = 0;
        int max = 0;
        for (int a1 =n;a1>=0;a1--){
            for (int a2 = n;a2>=0;a2--){
                for (int a3 = n;a3>=0;a3--){
                    if ((a1+a2)%2==0 && (a2+a3)%3==0 && (a1+a2+a3)%5==0){
                        result = a1+a2+a3;
                        max = max>result?max:result;
                    }
                }
            }
        }
        System.out.println(max);
    }
}
复制代码

转载于:https://juejin.im/post/5abb7af36fb9a028e33b7f41

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值