SDUT-3275 LCM的个数(JAVA*)

LCM的个数

Time Limit: 1000 ms  Memory Limit: 65536 KiB
Problem Description

对于我们来说求两个数的LCM(最小公倍数)是很容易的事,现在我遇到了一个问题需要大家帮助我来解决这问题,问题是:给你一个数n,然后统计有多少对(a<=b) LCM(a,b)=n;例如LCM(a,b)=12; 即(1,12),(2,12),(3,12),(4,12),(6,12),(12,12),(3,4),(4,6);

Input
 

输入数组有多组,每组数据包含一个整数n(n<=10^9);

Output
 

输出每组数据的对数。

Sample Input
2
3
4
6
Sample Output
2
2
3
5
Hint
 
Source

fmh

参考:https://blog.youkuaiyun.com/challengerrumble/article/details/46401347

package leslie_w;

//import java.io.*; //两个数最小公倍数为乘积除以最大公约数
//import java.math.*;
//import java.text.*;
//import java.math.BigInteger;
import java.util.*;

public class Main {

	public static int f(int a, int b) {
		if (b == 0)
			return a;
		return f(b, a % b);
	}

	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			int n = cin.nextInt();
			int num = 0, sum = 0;
			int a[] = new int[108611];
			for (int i = 1; i * i <= n; i++) {
				if (n % i == 0) {
					a[num++] = i;
					if (i * i != n) // n必然可拆分为两个因子a*b(一定是a<b),且i*i==n时因子只保留一次
						a[num++] = n / i;
				}
			}
			for (int i = 0; i < num; i++) {
				for (int j = i; j < num; j++) {
					if (a[i] / f(a[i], a[j]) * a[j] == n) // 先使数据缩小,避免a[i]和a[j]直接相乘得到的结果从int范围溢出
						sum++;
				}
			}
			System.out.println(sum);
		}
		cin.close();
	}
}


### Java 加密数据 对于Java加密数据的操作,通常会涉及到多种不同的算法和技术。在Java中实现加密功能主要依赖于`javax.crypto`包以及相关的类库。 #### 使用AES进行加密解密操作 下面是一个简单的例子展示如何利用AES(高级加密标准)来完成字符串的加解密工作: ```java import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; public class AESUtil { private static final String ALGORITHM = "AES"; public static byte[] encrypt(String content, String password) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance(ALGORITHM); kgen.init(128); SecretKey secretKey = kgen.generateKey(); byte[] enCodeFormat = secretKey.getEncoded(); SecretKeySpec key = new SecretKeySpec(enCodeFormat, ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM);// 创建密码器 byte[] byteContent = content.getBytes("utf-8"); cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化 return cipher.doFinal(byteContent); } public static byte[] decrypt(byte[] content, String password) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance(ALGORITHM); kgen.init(128); SecretKey secretKey = kgen.generateKey(); byte[] enCodeFormat = secretKey.getEncoded(); SecretKeySpec key = new SecretKeySpec(enCodeFormat, ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM);// 创建密码器 cipher.init(Cipher.DECRYPT_MODE, key);// 初始化 return cipher.doFinal(content); } } ``` 此代码片段展示了基本的AES加密和解密方法[^4]。需要注意的是,在实际应用环境中应当更加严谨地处理秘钥管理等问题,并且应该根据具体需求调整参数配置。 另外关于SDUT 7-17的具体内容并未提供足够的背景信息以便直接关联到上述主题上,请提供更多细节或者澄清所指的内容范围。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值