现在的位置: 首页 > 综合 > 正文

UVA – 11526(a/b式子计算)

2019年04月03日 ⁄ 综合 ⁄ 共 332字 ⁄ 字号 评论关闭

站在当前的i考虑的话  n/i=p;  假设j为最大的满足 k/j >= p 的整数,j <= k/p; 所以 j最大为 floor(k/p);重复这样计算即可;

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int main()
{
    LL n;
    int T;
    scanf("%d",&T);
    while(T--){
           scanf("%lld",&n);
           LL res=0;
           for(LL i=1;i<=n;){
                LL p = n/i;
                LL j = n/p;
                res+=(j-i+1)*p;
                i=j+1;
           } 
           printf("%lld\n",res);
    }
   return 0;
}

抱歉!评论已关闭.