当前位置:网站首页>Huawei machine test question -- hj76 nikochus theorem
Huawei machine test question -- hj76 nikochus theorem
2022-04-22 23:13:00 【Qingyun Xiaofan】
describe
To test the Nicolas Theorem , namely : Any integer m All the cubes can be written as m The sum of consecutive odd numbers .
for example :
1^3=1
2^3=3+5
3^3=7+9+11
4^3=13+15+17+19
Enter a positive integer m(m≤100), take m The cube of is written as m Output in the form of the sum of consecutive odd numbers .
Data range :1\le m\le 100\1≤m≤100
Advanced : Time complexity :O(m)\O(m) , Spatial complexity :O(1)\O(1)
Input description :
Enter a int Integers
Output description :
Output after decomposition string
Example 1
Input :
6
Copy output :
31+33+35+37+39+41
#include <iostream>
#include <vector>
#include <sstream>
std::string itoa(int num)
{
std::stringstream oss;
oss << num;
return oss.str();
}
void nikochus(int n)
{
int coub = n * n * n;
int tempi = n * n - n + 1; // Record the coordinates at the beginning of each accumulation
if(tempi % 2 == 0)
{
tempi -= 1;
}
std::vector<std::string> rtnVect;
while(1)
{
int sum = 0;
int start = tempi;
while(start < coub / 2)
{
sum += start;
start += 2;
int end = start;
if(sum == coub)
{
for(int k = tempi; k < end; k += 2)
{
rtnVect.push_back(itoa(k));
rtnVect.push_back("+");
}
std::vector<std::string>::iterator iter = rtnVect.begin();
while(iter != rtnVect.end()-1)
{
std::cout << *iter++;
}
std::cout << std::endl;
return;
}
if(sum > coub)
{
break;
}
}
tempi += 2;
sum = 0;
}
// print(rtnVect);
}
//6 31+33+35+37+39+41
int main()
{
int n;
while(std::cin >> n)
{
nikochus(n);
}
return 0;
}
版权声明
本文为[Qingyun Xiaofan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222309181506.html
边栏推荐
- Le Code [SWIFT] déclenche l'événement de clic d'uibutton
- 伦敦金在哪里开户安全些?
- [leetcode refers to the path with a certain value in offer 34. Binary tree (medium)]
- 操作系统知识点(可学习,可复习,可面试)
- (JS)利用String对象的属性和方法实现注册和登录功能,要求用户名长度在3-10范围内,密码在6-20位
- 光学指纹模组解锁方案设计指纹锁方案
- [original] [open source] C WinForm DPI adaptive scheme, sunnyui three-step solution
- JS计算圆的周长和面积
- Go语言-使用协程高效计算0-2000内每个数的累加
- Codeforce1669 A和B
猜你喜欢

软件测试(1)
![[hctf 2018] Unicode spoofing of admin](/img/67/227f3ec20f73ab96b2f4bfb735bfd4.png)
[hctf 2018] Unicode spoofing of admin

Pytorch 卷积核填充和步幅、多输入多输出通道、池化层

Basic use and principle of Minio

Detailed explanation of SQL language

VI / VIM 编辑器基本操作

Chenshi industrial machine vision | weld detection solution

一个快速追踪密切接触者的开源脚本方案

Unity uses newtonsoft JSON plug-in realizes the conversion of XML and JSON data

正则表达式——IP地址匹配
随机推荐
加密模式介绍(ECB、CBC、PCBC、CFB、OFB、CTR)
Regular expression -- IP address matching
English | day13,14 x sentence true research daily sentence (parallel and nested structure)
Core technology of GDB debugger - ptrace system call and use example
辰视工业级机器视觉 | 焊缝检测解决方案
Codeforces Round #784 (Div. 4)
Ignition Modbus
LeetCode 414. The third largest number (simple, array) day13
how to become professional
win10 安装mujoco,mujoco_py,gym
Redis部署
SystemVerilog 验证-测试平台编写指南学习笔记(1):数据类型
高数 | 【多元函数微分学及应用】易错题 及 李林880详解
Software test (1)
[HCTF 2018]admin之unicode欺骗
Pytorch convolution kernel filling and stride, multiple input and multiple output channels, pool layer
记录使用PageHelper时,使用Example添加排序失效问题
How to install cadence software
VI / VIM 编辑器基本操作
2022-4-22作业-MySQL单表查询