牛客练习赛25

博客内容主要给出了牛客网一道题目的链接,包含输入描述、输出描述、输入、输出、说明和备注等信息,还给出了转载来源。

链接:https://www.nowcoder.com/acm/contest/158/A
来源:牛客网

q次询问,每次给一个x,问1到x的因数个数的和。

输入描述:

第一行一个正整数q ;
接下来q行,每行一个正整数 x

输出描述:

共q行,每行一个正整数表示答案

示例1

输入

复制
4
1
2
3
10

输出

复制
1
3
5
27

说明

1的因数有1

2的因数有1,2

3的因数有1,3

以此类推

备注:

1<=q<=10 ,1<= x<=10^9

1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <string>
 7 #include <deque>
 8 #include <vector>
 9 #include <set>
10 #include <map>
11 #include <cmath>
12 using namespace std;
13 #define ll long long 
14 int t,n;
15 ll solve(int n)//1~n中所有因子的个数和
16 {
17     ll ans=0;
18 for(int i=1,last;i<=n;i=last+1){//sqrt(N)的复杂度,i==last+1 19 last=n/(n/i);//分块 : last : 出现n/i次的最大因子 5/3 5/4 5/5 3 4 5 都出现了一次 20 ans+=(ll)(n/i)*(last-i+1);//n/i :i作为因子共出现的次数 21 } 22 return ans; 23 } 24 int main() 25 { 26 scanf("%d",&t); 27 while(t--) 28 { 29 scanf("%d",&n); 30 printf("%lld\n",solve(n)); 31 } 32 return 0; 33 }

 

转载于:https://www.cnblogs.com/tingtin/p/9533033.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值