UVA 7340 Sum of MSLCM
来源:互联网 发布:淘宝热卖商品排行榜 编辑:程序博客网 时间:2024/06/18 06:41
思路在代码上。。。
1.筛法求素打表4000ms++
2.技巧哈。。。20ms++
#include<stdio.h>#include<stdio.h>#define N 20000001long long num[20000002];long long sum[N+1];void init(){ for(int i=1;i<=N;i++) { for(int j=i;j<=N;j+=i) num[j]+=i; } sum[1]=0; for(int i=2;i<=N;i++) { sum[i]=sum[i-1]+num[i]; }}int main(){ init(); int n; while(scanf("%d",&n)==1&&n) { printf("%lld\n",sum[n]); }}
20ms的了。。。
#include<stdio.h>#include<string.h>#define ll long long#include<algorithm>using namespace std;int main(){ ll r,l,n,i,ans,sum; while(~scanf("%lld",&n)) { ans=0; sum=0; for(i=2ll;i*i<=n;i++)///i数据范围是long long { r=(n)/(i-1);///连续相同的下一个区间最大值 ///10:r:( 10) 9 8 7 6 l:(5(2)) 4(2) 3(3) 2(5) 1(10) l=n/i;/// 如上表 ans+=(l)*i;/// 左边的 2(5); ///存在五个数的出现一次 那么就存在2 出现5次 ans+=(i-1)*(r+(l+1))/2*(r-l);/// (i-1)出现的次数 r+(l+1)/2区间内点的平均值 r-l代表区间长度 // printf("ans:%lld\n",ans); } i-=1ll; if(n!=i*i) ans+=n/i*i;///特判一种n如果==i*i 就不需要了 因为中间的3(3) 没加上。。。。///注意i是从2开始的,,从一开始的话也要特判就是减。。。 printf("%lld\n",ans); }}
0 0
- UVA 7340 Sum of MSLCM
- UVALive 7340 Sum of MSLCM
- UVA 1730 Sum of MSLCM 【数学】【二分】
- UVALive 7340 Sum of MSLCM【数学】
- Game of Sum UVA
- Sum of powers UVA
- uva 10891 Game of Sum
- UVA 10891 Game of Sum
- UVa 10891 Game of Sum
- Uva-10891-Game of Sum
- Uva 10891 Game of Sum
- Uva - 10891 - Game of Sum
- uva 10891 - Game of Sum
- uva 10891 game of sum
- UVA 10891 Game of Sum
- UVa 10891 - Game of Sum
- UVA 10891 Game of Sum
- uva 10891 - Game of Sum
- Android中AsyncTask的介绍,示例和原理分析
- react-router 学习笔记
- poj3348 Cows【凸包面积】
- Android 网络请求 框架
- 1023. Have Fun with Numbers (20)
- UVA 7340 Sum of MSLCM
- centos7环境下搭建storm集群
- 浏览器兼容问题项目总结(五)table中td和li高度问题
- (原创)分享自己写的几个工具类(四)BigDecimal精确计算
- MTK lk源码解析7( lk 阶段aboot.c 解析)
- js中如何查看原型
- 手机端切图转静态页工具文档
- 常见的排序算法示例(2)-选择排序、插入排序、希尔排序
- Linux入门——vim编辑器简单操作