大整数的基本处理和求两两互素的数组

来源:互联网 发布:淘宝网首页女装连衣裙 编辑:程序博客网 时间:2024/04/29 08:10

package com.ps.test;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
public class Tobinary {
 @SuppressWarnings("unused")
 public static void main(String[] args) {
  //大整数的处理
//  BigInteger d1 = new BigInteger("3");
//  System.out.println(d1.bitLength());
//  BigInteger d = new BigInteger("6");
//  BigInteger d2 = d1.multiply(d);
//  System.out.println(d2);
//  System.out.println(d2.bitLength());
//  int i = getBit(9,6);
//  System.out.println(i);
//  BigInteger d1 = new BigInteger(String.valueOf(i));
//  System.out.println(Math.pow(3,2));
  /**
   * 在指定范围类找到两两互素的整数
   */
  List list= new ArrayList();
  double num = 19;//根据需求给定初速值
  list.add(num);
  for(double l=16;l<32;l++){//指定范围为16到32
   int temp = 0;
   for(int i=0;i<list.size();i++ ){
    if(1==getBit(l,(Double)list.get(i))){
     temp++;
    }
    if(temp==list.size()){
     list.add(l);
    }
   }
   if(list.size()==9)break;//根据需求看需要几个
  }
  for(int j=0;j<list.size();j++){
   System.out.println(j+"----"+list.get(j));
  }
 }
 /**
  * 求两两互素的递归
  */
 public static double getBit(double a, double b)
  {
   if(b == 0)
          return a;
      return getBit(b, a % b);
  }
}

原创粉丝点击