洛谷 P1403 [AHOI2005]约数研究

匿名 (未验证) 提交于 2019-12-02 23:59:01

洛谷 P1403 [AHOI2005]约数研究


思路:Kelin的题解

代码(自己的丑代码)

#include <iostream> #include <cstdio> int main(){ 	int n; 	long long ans = 0; 	scanf("%d", &n); 	for(int i = 1; i <= n; ++i) 	{ 		ans += n/i; 	} 	printf("%lld\n", ans); 	return 0; } 

以及优化后

#include <iostream> #include <cstdio> int main(){ 	int n; 	long long ans = 0; 	scanf("%d", &n); 	for(int i = 1, j; i <= n; i = j+1) 	{ 		j = n / (n/i); 		ans += (n/i) * (j-i+1); 	} 	printf("%lld\n", ans); 	return 0; } 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!