当前位置:网站首页>3. Continuous integer
3. Continuous integer
2022-04-23 06:08:00 【linsa_ pursuer】
A positive integer may be expressed as m(m>1) The sum of consecutive positive integers ,
Such as :
15=1+2+3+4+5 15=4=5=6 15=7=8
Judge a given integer n Can it be expressed as continuous m(m>1) Sum of positive integers
Input : There's only one whole number n(1<n<2^30+1);
Output : if n Can represent continuous m(m>1) The sum of two positive integers outputs “YES”, Otherwise output “NO”.
package com;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
System.out.println(hasNum(s.nextInt()));
}
public static String hasNum(int n){
//2n = (2a+p-1)p n/2>=a>0 p>1
for(int i=1; i<n/2; i++){
for(int j=2; j<n; j++){
if(2*n == (2*i+j-1)*j){
return "YES";
}else if(2*n < (2*i+j-1)*j){
break;
}
}
}
return "NO";
}
}
Such as :
Input :15
Output :YES
版权声明
本文为[linsa_ pursuer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533259920.html
边栏推荐
- Pytorch learning record (IX): convolutional neural network in pytorch
- Postfix变成垃圾邮件中转站后的补救
- 图解numpy数组矩阵
- Algèbre linéaire chapitre 1 - déterminants
- How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation
- Framework analysis 1 Introduction to system architecture
- Implementation of displaying database pictures to browser tables based on thymeleaf
- PyTorch笔记——通过搭建ResNet熟悉网络搭建方式(完整代码)
- Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
- The official website of UMI yarn create @ umijs / UMI app reports an error: the syntax of file name, directory name or volume label is incorrect
猜你喜欢
线性代数第二章-矩阵及其运算
List segmentation best practices
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
Filebrowser realizes private network disk
PyQy5学习(二):QMainWindow+QWidget+QLabel
Practical operation - Nacos installation and configuration
Anaconda安装PyQt5 和 pyqt5-tools后没有出现designer.exe的问题解决
PyQy5学习(三):QLineEdit+QTextEdit
Pytorch learning record (XII): learning rate attenuation + regularization
线代第四章-向量组的线性相关
随机推荐
自动控制(韩敏版)
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
Pytorch学习记录(十三):循环神经网络((Recurrent Neural Network)
Multithreading and high concurrency (3) -- synchronized principle
C3p0 database connection pool usage
Latex quick start
Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
Implementation of displaying database pictures to browser tables based on thymeleaf
Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
Class loading and classloader understanding
常用编程记录——parser = argparse.ArgumentParser()
Latex快速入门
Pyqt5 learning (I): Layout Management + signal and slot association + menu bar and toolbar + packaging resource package
线性代数第二章-矩阵及其运算
ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
lambda expressions
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
The user name and password of users in the domain accessing the samba server outside the domain are wrong
PyQy5学习(二):QMainWindow+QWidget+QLabel
Pyemd installation and simple use