プロジェクトオイラー問179

Problem 179 「連続する正の約数」 †
n と n + 1 の正の約数の数が同じになる 1 < n < 10^7 の整数は幾つあるか. 例として, 14 の正の約数は 1, 2, 7, 14 であり, 15 の正の約数は 1, 3, 5, 15 である.



1000万くらいなら下から数え上げるのが一番楽です。


#include<stdio.h>
#include<string.h>
const int LIMIT=1000*10000;
int count[LIMIT];

int main(){
	memset(count,0,sizeof(count));
	for(int i=1;i<LIMIT;i++){
		for(int j=i;j<LIMIT;j+=i){
			count[j]++;
		}
	}
	int ans=0;
	for(int i=1;i+1<LIMIT;i++){
		if(count[i]==count[i+1])ans++;
	}
	printf("ans=%d\n",ans);
}

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2016年01月09日 03:45