import java.util.Scanner; //输入两个正整数m和n,求其最大公约数和最小公倍数.15 20 5 public class Test { public static void main(String[] args) { int n = inNumber(); int m = inNumber(); int yue = 1; int bei = m*n; for (int i = 2; i < n*m; i++) { if (m % i == 0 && n %
public static void main(String[] args){ Scanner sc = new Scanner (System.in); int a,b; System.out.println("请输入两个正整数:"); a = sc.nextInt(); b = sc.nextInt(); System.out.println("您输入的数是:" + a +"和"+b); int age[] = new int[
两次DFS求树直径方法见 这里. 这里的直径是指最长链包含的节点个数,而上一题是指最长链的路径权值之和,注意区分. K <= R: ans = K − 1; K > R: ans = R − 1 + ( K − R ) ∗ 2; #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; ; struct n
python中对两个 list 求交集,并集和差集: 1.首先是较为浅白的做法: >>> a=[1,2,3,4,5,6,7,8,9,10] >>> b=[1,2,3,4,5] >>> intersection=[v for v in a if v in b] >>> intersection [1, 2, 3, 4, 5] >>> union=b.extend([v for v in a]) >>>
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 48364 Accepted Submission(s): 16581 Problem Description Nowadays, we all know that Computer College is the biggest department in H
概念: 最大公约数:两个整数共有因子中最大的一个 方法一: 如果两个数相等,则最大公约数为它本身,两个数不等,则用两个数依次除 两个数中最小的一个到 1,直到找到同时能被两个数除尽的那个数 代码清单: public static int gcd1(int x, int y) { int result = 0; // 最大公约数 int min = x > y ? y : x; // 两个整数中最小的数 if (x == y) { result = x; } else { for (int i =
import java.util.Scanner; public class Oujilide欧几里得 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int n=in.nextInt();//第一个数 int m=in.nextInt();//第二个数 System.out.print("最大公约数为");
def diff(listA,listB): #求交集的两种方式 retA = [i for i in listA if i in listB] retB = list(set(listA).intersection(set(listB))) print "retA is: ",retA print "retB is: ",retB #求并集 retC = list(set(listA).union(set(listB))) print "retC1 is