[最小公倍数] 给定两个正整数,计算这两个数的最小公倍数。
Java实现 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 import  java.util.ArrayList;import  java.util.Scanner;public  class  leastcommonmultiple {    public  int  f (int  a, int  b) {                  ArrayList<Integer> arrayList1 = new  ArrayList <Integer>();         ArrayList<Integer> arrayList2 = new  ArrayList <Integer>();                  for (int  i  =  2 ; a > 1 ; i++){             for (;(a % i) == 0 ; a /= i){                 arrayList1.add(i);             }         }         for (int  j  =  2 ; b > 1 ; j++){             for (;(b % j) == 0 ; b /= j){                 arrayList2.add(j);             }         }         int  size  =  0 ;         int  max  =  1 ;         int  temp  =  0 ;                  while (size < arrayList1.size()){             if  (arrayList2.contains(arrayList1.get(size))){                max = arrayList1.get(size) * max;                arrayList2.remove(arrayList2.indexOf(arrayList1.get(size)));                arrayList1.remove(size);                size = temp;             }else {                 temp = size += 1 ;             }         }         return  max;     }     public  static  void  main (String[] args)  {         Scanner  scanner  =  new  Scanner (System.in);         System.out.println("输入第一个数: " );         int  a  =  scanner.nextInt();         System.out.println("输入第二个数: " );         int  b  =  scanner.nextInt();         leastcommonmultiple  method  =  new  leastcommonmultiple ();         int  multiple  =  a * b / (method.f(a,b));         System.out.println("最小公倍数是" + multiple);     } } 
[素数判定] 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。
输入 
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
输出 
对于每个给定范围内的取值,如果表达式的值都为素数,则输出”OK”,否则请输出“Sorry”,每组输出占一行。
C 实现 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include <stdio.h>   int  sushu (int  n) {     int  i;      if (n < 2 )          return  0 ;      for (i = 2 ;i* i <= n;i ++){          if (n % i == 0 )              return  0 ;          else  ;      }  return  1 ;}  int  main () {     int  x, y, i, s;      while (scanf ("%d%d" , &x, &y)){          if (x == 0  && y == 0 )              break ;          for (i = x;i <= y;i ++){              s = i * i + i + 41 ;              if (! sushu(s)){                  printf ("Sorry\n" );                  break ;              }          }          if (i == y + 1 )              printf ("OK\n" );          }        return  0 ;  }