C#
#include <stdio.h>
#include <math.h>
int factor(long long sum);
int main(){
long long sum = 0L;
for(long long i = 1L;i>=0;i++){
sum += i;
if(factor(sum) > 500) break;
}
printf("%d",sum);
}
int factor(long long sum){
int count = 0;
for(long long i = 1;i <= sqrt(sum);i++){
if(sum % i == 0){
if(i * i == sum)
count++;
else
count+=2;
}
}
return count;
}
JAVA
package exercise;
public class _多约数的三角形数 {
public static void main(String[] args) {
long sum=0;
for(long i=1;i>=1;i++){
sum=count(i);
if(sum>500){
if(math(sum)>=500)
break;
}
}
System.out.println(sum);
}
private static long math(long n){
int count=0;
double j=Math.sqrt(n);
for(int i=1;i<=j;i++){
if(n%i==0&&n/i>0){
count+=2;
}else if(n/i<=0){
break;
}
}
if(count>=500)
System.out.println("数值:"+n+" 约数:"+count);
return count;
}
private static long count(long n){
long sum=0;
for(int i=1;i<=n;i++){
sum+=i;
}
return sum;
}
}
结果:76576500