华为OD机试真题 - 用连续自然数之和来
列方程 double L= (num * 2 + i - i * i) / 4.0;
如果 L 是整数就存在
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
System.out.println(getReslut(num));
}
public static int getReslut(int num) {
int count = 1;
for (int i = 1; i <= num / i; i++) {
double temp = (num * 2 + i - i * i) / 4.0;
if (temp == (int)temp)
count++;
}
return count;
}
如果 L 是整数就存在
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
System.out.println(getReslut(num));
}
public static int getReslut(int num) {
int count = 1;
for (int i = 1; i <= num / i; i++) {
double temp = (num * 2 + i - i * i) / 4.0;
if (temp == (int)temp)
count++;
}
return count;
}
全部评论
相关推荐
码农索隆:我就问一下,你性格真内向吗
点赞 评论 收藏
分享
有礼貌的干饭人G了:校友直接投就好了,我简历上项目就只有一个原封不动的外卖也进了一家不错的独角兽
点赞 评论 收藏
分享

点赞 评论 收藏
分享