上海耀乘健康科技公司笔试
两道算法
1.给平面三个点判断能组成多少个三角形。暴力n^3过了
2.给一个合数,求他的分解质因数,以每个因数的底数和指数输出,比如12 = 2 *2 * 3, 输出[[2,2],[3,1]] , 合数范围为2~2^31 - 1。
只过了20%, 太菜了,后面看题解学会了。代码如下:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
while (n -- > 0){
int a = scanner.nextInt();
for (int i = 2 ; i <= a/i ; i++){
// i 为什么一定是质数? 因为如果是合数,应该被他的因子分解了已经。
if (a % i == 0){
int cnt = 0;
while (a % i == 0){
a /= i;
cnt++;
}
System.out.println(i + " " + cnt);
}
}
if(a > 1) System.out.println(a + " " + 1);
System.out.println();
}
}
}
1.给平面三个点判断能组成多少个三角形。暴力n^3过了
2.给一个合数,求他的分解质因数,以每个因数的底数和指数输出,比如12 = 2 *2 * 3, 输出[[2,2],[3,1]] , 合数范围为2~2^31 - 1。
只过了20%, 太菜了,后面看题解学会了。代码如下:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
while (n -- > 0){
int a = scanner.nextInt();
for (int i = 2 ; i <= a/i ; i++){
// i 为什么一定是质数? 因为如果是合数,应该被他的因子分解了已经。
if (a % i == 0){
int cnt = 0;
while (a % i == 0){
a /= i;
cnt++;
}
System.out.println(i + " " + cnt);
}
}
if(a > 1) System.out.println(a + " " + 1);
System.out.println();
}
}
}
全部评论
请问有后续吗
是acm模式?
大佬的算法是在什么平台上学的
第二段代码有点问题把
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
02-05 13:16
南京邮电大学 Java
等闲_:其实agent开发和语言没关系,只要能稳定落地可观测,有业务价值的agent就是好agent,而各种语言的agentkit是企业基建必要的,是一些maas平台的agent模块的重要组成,需要提供零代码的能力让M端的同***营agent,所以不要过于纠结这些,真正要看的是模型工程化这整条链路,能做什么,怎么做更方便 点赞 评论 收藏
分享