zoukankan      html  css  js  c++  java
  • 平方数

    package CHobery;
    
    
    /**
     * 给定7个数字2,3,5,6,7,8,9的全排列共7!个
     * 7位数中有多少个平方数。试着求出这些7位平方数
     * @author Administrator
     *
     */
    public class Main1 {
    
    	public static long b = 0,c = 0,d = 0,y = 0,g = 0;
    	public static int m = 0;
    	public static int n = 0;
    	public static int k = 0;
    	public static int [] f = new int[10];
    	public static void main(String[] args) {
    		c = (long) Math.sqrt(2356789);
    		d = (long)Math.sqrt(9876532);
    		//1:初始化数组f的数字全部是0
    		init(f);
    		//2:解决问题
    		solution(c,d);
    	}
    	private static void solution(long c, long d) {
    		//循环遍历
    		for (y = c; y<=d;y++) {
    			b = y*y;
    			g = b;
    			while (g > 0) {
    				k = (int) (g%10);
    				f[k] = f[k]+1;
    				g = g/10;
    			}
    			for (m = 0,k = 0;k <=9;k++) {
    				if (f[k] > 1) {
    					m = 1;//标记有重复的数字
    				}
    			}
    			if (m ==0 && f[0]+f[1]+f[4] == 0) {
    				n++;//数字中不包含0,1,4,的数字
    				System.out.printf("%ld = (%ld~2)",b,y);
    				if (n%3 == 0) {
    					System.out.printf("
    ");
    				}
    			}
    			
    		}
    		
    	}
    	public static void init(int[]array){
    		for (int i = 0;i<array.length;i++) {
    			array[i] = 0;
    		}
    	}
    }
    

      

  • 相关阅读:
    PHP创建socket服务
    linux配置PS1
    几个常用的linux命令
    MongoDB的分片集群搭建
    django-admin 配置
    django使用mysql数据库
    Django知识
    docker 监控之 cadvisor
    shell 拾遗
    shell 基数数值方法
  • 原文地址:https://www.cnblogs.com/airycode/p/5766543.html
Copyright © 2011-2022 走看看