平方数

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("\n");
				}
			}
			
		}
		
	}
	public static void init(int[]array){
		for (int i = 0;i<array.length;i++) {
			array[i] = 0;
		}
	}
}

  

转载于:https://www.cnblogs.com/airycode/p/5766543.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值