学校的作业
c吧
全部回复
仅看楼主
level 1
哥哥们,这个为什么一直显示超时
#include <stdio.h>int main() { int m, n; int count = 0; scanf("%d%d", &m, &n); int i = m; while (i <= n) { int sum = 0; int j = 1; while (j < i) { if (i % j == 0) { sum += j; } j++; } if (sum == i) { count++; } i++; } printf("%d", count); return 0;}
2025年05月04日 02点05分 1
吧务
level 11
嵌套循环极其耗费时间,需要优化算法!
2025年05月04日 07点05分 3
怎么改呀,要求是判断区间内的完数的个数
2025年05月04日 10点05分
吧务
level 11
不要无脑区间遍历验证,根据完数的性质做
2025年05月04日 11点05分 4
根据性质2,for(p = 2;;p++){ if(pow(2, p-1)*(pow(2,p)-1)<n) continue; if(pow(2,p-1)*(pow(2,p)-1)>m) break; if(pow(2, p) - 1是梅森素数){ counter++; printf("%d\n", pow(2,p-1)*(pow(2,p)-1)); } }
2025年05月04日 11点05分
@油炸不良人 谢谢,哥
2025年05月04日 12点05分
吧务
level 11
将就看下,细节再改改
2025年05月04日 12点05分 5
1