The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Let us list the factors of the first seven triangle numbers:
1: 1
3: 1,3
6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28
We can see that 28 is the first triangle number to have over five divisors.
What is the value of the first triangle number to have over five hundred divisors?
#include <stdio.h> #include <stdbool.h> int trinumber(int n) { if(n % 2 == 0) { return (n / 2) * (n + 1); } else { return ((n + 1) / 2) * n; } } bool divnum(int n) { int i, sum = 0; for(i = 1; i * i < n; i++) { if(n % i == 0) { sum += 2; } } if(i * i == n) sum++; if(sum > 500) return true; else return false; } void solve(void) { int i, num; num = 0; for(i = 1; ; i++) { if(divnum(trinumber(i))) { printf("%d\n",trinumber(i)); break; } } } int main(void) { solve(); return 0; }
Answer:
|
76576500 |
相关推荐
const isNumberDivisibleByOtherNumber = require ( "is-number-divisible-by-other-number" ) ;isNumberDivisibleByOtherNumber . isSixDivisibleByThree ( ) ; // => trueisNumberDivisibleByOtherNumber . ...
python python_leetcode题解之Binary Prefix Divisible By 5.py
**Problem Statement:** If \(3x + 7y\) is divisible by 11, which of the following must also be divisible by 11? - **Concepts Involved:** Number theory, divisibility. - **Solution Approach:** Use the ...
标题中的“en2_src.rar_divisible_模2除法”暗示了这是一个关于使用模2除法(也称为二进制除法)实现流加解密算法的资源包。描述中提到,该算法专注于处理至少8字节且字节数可被4整除的数据,这表明算法设计时考虑到...
The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number ...
bool divisibleBy3And5(int number) { if (number % 3 == 0 && number % 5 == 0) { return true; } else { return false; } } int main() { int number = 30; if (divisibleBy3And5(number)) { std::cout ...
### 十大理由选择可分割负载理论:分布式计算的关键 #### 深入理解可分割负载理论(DLT) 在当今高度发达的信息时代,多处理器系统与数据密集型计算日益普遍,这催生了对高效计算负载调度的需求,尤其是那些可以在...
在这个“算法设计与分析期末”动态规划的第一题中,我们关注的是“Largest Divisible Subset”(最大可除子集)问题。这个题目要求找到一个整数数组中,最大的子集,其中所有元素两两之间可以被整除。 首先,我们...
Clatworthy可分组设计的完整推广,高斐,葛根年,部分平衡不完全区组设计(PBIBDs)有着悠久的历史,并已广泛用于农业和工业试验。自Clatworthy关于两个结合类的部分平衡设计一书于1973�
If the number is divisible by 3, output "Fizz." If the number is divisible by 5, output "Buzz." If the number is divisible by both 3 and 5, output "FizzBuzz." If the number is not divisible by any of...
When the number is divisible by 3 then instead of printing the number it should print "Fizz". `When the number is divisible by 5, then instead of printing the number it should print "Buzz".` `And ...
`When the number is divisible by 5, then instead of printing the number it should print "Buzz".` `And if the number is divisible by both 3 and 5 e.g. 15 then instead of the number it should prin
在数论部分,包括natural number、positive number、negative number、odd integer、even integer、integer、whole number、positive whole number、negative whole number、consecutive number、real number、...
可被 n 条消息整除的工具 由 Ryan Jackson 于 2015 年 2 月 11 日创建 目的 该库的目的是提供一种基于整数数组(列表)使用 JavaScript 将消息输出到控制台的方法。 基本算法是这样的: 给定一个正整数(或整数最大...
- `inverse` 是倒数,`composite number` 是合数,如 4, 6, 8, 9, 10, 12, 14, 15 等。 - `prime number` 是质数,如 2, 3, 5, 7, 11, 13, 15 等,需要注意的是,所有质数除了2之外都是奇数。 以上这些词汇是数学...
Prime number program in c: c program for prime number,... Prime number logic: a number is prime if it is divisible only by one and itself. Remember two is the only even and also the smallest prime number
12. **开发者(Developer)** - 开发者是指编写和维护程序的人。 - 在Java开发中,开发者需要掌握Java语言及相关工具。 13. **Java API** - Java API是一组预先定义好的类和接口的集合,供开发者在开发Java...
ACM试题Problem K:Ones ...= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1 s. How many digits are in the smallest such a multiple of n?
("number is not divisible by 4, 3, or 2"); } ``` #### 循环语句 ```rust let mut count = 0; 'counting_up: loop { println!("count = {}", count); let mut remaining = 10; loop { println!("remaining ...
对数和对 您将得到一个整数数组,和一个正整数。 查找并打印对和+可整除的对数。 例如和。 我们符合条件的三对是和。 功能说明 在下面的编辑器中完成divisibleSumPairs函数。 它应该返回符合条件的对的整数计数。...