全部评论
第二题回溯法可以做,有点像剑指offer最后一题,不过把数字改成字符,出发点改成@的位置。 第一题看了几遍题目之后放弃了。。😥
分享
大神啊。。。算法题第一道和倒数第二道直接没写,其他三题,本地通过,提交不通过......凉凉了...🤣🤣
分享
阿里巴巴
官网直投
第一道题感觉写对了 但是只通过了40% 第二道提没给输入的case 犹豫了半天 没写完(但是思路通了) 求平安科技给个机会吧
分享
输入总弄不对,时间都花在弄输入上了,求教怎么写啊
分享
头条也没这样难吧😂平安想干啥
分享
第一题只过了80%也不知道是为什么... import java.util.Scanner; public class Main { private static int maxN = 5201314; private static boolean[] primes = new boolean[maxN]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); setPrime(); for (int i = 2; i < n; i++) { if (quickPow(i, n - 1, n) == 1) { if (isPrimeRoot(i, n - 1)) { System.out.println(i); return; } } } System.out.println(-1); sc.close(); } private static boolean isPrimeRoot(int g, int P) { for (int i = 2; i < P; i++) { if (!primes[i] && quickPow(P, 1, i) == 0) if (quickPow(g, P / i, P + 1) == 1) return false; while (P % i == 0) P /= i; } return true; } private static void setPrime() { for (int i = 2; i < maxN; i++) if (!primes[i]) for (int j = i * 2; j < maxN; j += i) primes[j] = true; } private static int quickPow(int a, int b, int mod) { int ans = 1; for (; b != 0; b /= 2) { if (b % 2 == 1) ans = (ans * a) % mod; a = (a * a) % mod; } return ans; } } 第二题用dfs做的ac了但是是不是就只有一个用例...其实感觉自己写的有点问题~
分享
哈哈哈哈。
分享
求问,没有AC是不是就是0分啊?
分享
老哥,有收到面试通知么,我也和你一样两道都没通过,第二道题提交了没通过,第一道没提交。😰好菜
分享
你们两道编程题?为什么我的是五道编程题?!
分享
相关推荐
点赞 评论 收藏
转发
点赞 评论 收藏
转发