腾讯2019秋招软件开发笔试题解
第一题
static int cnt = 0; static int[] prime = new int[1000006]; public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); prime(n); long ans = 2; for (int i = 0; i < cnt; i++) { int p = prime[i]; long a = 1; while (a * p <= n) { a *= p; } long b = (n / a + 1) * a; ans = Math.max(b, ans); } System.out.println(ans); } private static void prime(int maxnum) { boolean[] notPrime = new boolean[maxnum+1]; notPrime[0] = notPrime[1] = true; int i, j; for (i = 2; i <= maxnum; i++) { if (!notPrime[i]) { prime[cnt++] = i; for (j = i + i; j <= maxnum; j += i) { notPrime[j] = true; } } } }
第二题
import java.util.*; public class Main { static boolean[][] isReach; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int m = scan.nextInt(); isReach = new boolean[n][n]; for (int i = 0; i < m; i++) { isReach[scan.nextInt() - 1][scan.nextInt() - 1] = true; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j && isReach[i][j]) { dfs(i, j, n); } } } int[][] count = new int[n][2]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (isReach[i][j]) { count[i][0]++; count[j][1]++; } } } int res = 0; for (int i = 0; i < n; i++) { if (count[i][1] > count[i][0]) { res++; } } System.out.println(res); } public static void dfs(int begin, int end, int n) { for (int i = 0; i < n; i++) { if (i != end) { if (isReach[end][i] && !isReach[begin][i] && begin != i) { isReach[begin][i] = true; dfs(begin, i, n); } } } } }
第三题
public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) {//注意while处理多个case int t = in.nextInt(); for(int i = 0; i < t; i++) { int A = in.nextInt(); int B = in.nextInt(); int C = in.nextInt(); boolean flag = false; for(int j = 1; j <= 100; j++) { if(j * A % B == C) { flag = true; break; } } if(flag) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
#秋招##腾讯##题解#