首页 技术 正文
技术 2022年11月15日
0 收藏 307 点赞 3,547 浏览 633 个字

先举个例子,假如给你的数是100的话,将100/2=50;是不是就是100除100-51之间的数取整为1;

100/3=33;100除50到34之间的数为2,那么这样下去到sqrt(100);就可以求得100除以sqrt(100)+1到100之间数的和,也就是后90项的和以求得。

剩余的前10项直接代公式求就行了。

复杂度为2*sqrt(N);

http://lightoj.com/volume_showproblem.php?problem=1245

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<stdlib.h>
5 #include<string.h>
6 #include<math.h>
7 typedef long long ll;
8 using namespace std;
9 int main(void)
10 {
11 ll i,j,k,p,q,n;
12 scanf("%lld",&n);
13 for(i=1; i<=n; i++)
14 {
15 scanf("%lld",&p);
16 ll x=0;ll tt=0;
17 k=p;
18 for(j=2;j<=sqrt(p);j++)
19 {
20 x+=(k-(p/j))*(j-1);
21 k=p/j;
22 }
23 for(j=k;j>=1;j--)
24 {
25 x+=p/j;
26 }
27 printf("Case %lld: ",i);
28 printf("%lld\n",x);
29 }
30 }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,026
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,517
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,364
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,145
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,779
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,856