建信金融科技春季全国笔试卷B编程题

解题思路:

四重循环遍历。

解题代码:

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int A = scanner.nextInt(); int B = scanner.nextInt(); int C = scanner.nextInt(); int D = scanner.nextInt(); int count = 0; for (int a = 1; a <= A; a++) { for (int b = 1; b <= B; b++) { for (int c = 1; c <= C; c++) { for (int d = 1; d <= D; d++) { if (((a - b) % 3 == 0) && ((b + c) % 5 == 0) && ((a * c) % 4 == 0) && getGCD(a, d) == 1) { count++; } } } } } System.out.println(count); } private static int getGCD(int x, int y) { for (int a = Math.min(x, y); a >= 1; a--) { if (x % a == 0 && y % a == 0) { return a; } } return 1; } }

解题结果

原文链接:https://blog.csdn.net/Kangyucheng/article/details/105168684?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165277097916781432970800%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165277097916781432970800&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-23-105168684-null-null.nonecase&utm_term=%E7%A7%91%E6%8A%80

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
文明发言,共建和谐米科社区
提交
头像

昵称

取消
昵称表情图片