题意:输入n(在32位带符号整数范围内),计算下面C++函数的返回值。
分析:合并同类项加速一下即可。
假设n为100,则n/34=2,那么通过n/2=50,可知道34到50的结果都是2,以此加速。
#pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #include<cmath> #include<iostream> #include<sstream> #include<iterator> #include<algorithm> #include<string> #include<vector> #include<set> #include<map> #include<stack> #include<deque> #include<queue> #include<list> #define Min(a, b) ((a < b) ? a : b) #define Max(a, b) ((a < b) ? b : a) const double eps = 1e-8; inline int dcmp(double a, double b) { if(fabs(a - b) < eps) return 0; return a < b ? -1 : 1; } typedef long long LL; typedef unsigned long long ULL; const int INT_INF = 0x3f3f3f3f; const int INT_M_INF = 0x7f7f7f7f; const LL LL_INF = 0x3f3f3f3f3f3f3f3f; const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f; const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1}; const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1}; const int MOD = 1e9 + 7; const double pi = acos(-1.0); const int MAXN = 16384 + 10; const int MAXT = 10000 + 10; using namespace std; int main(){ int T; scanf("%d", &T); while(T--){ LL n; scanf("%lld", &n); LL ans = 0; for(LL i = 1; i <= n; ++i){ LL tmp = n / i; LL et = n / tmp; ans += (et - i + 1) * tmp; i = et; } printf("%lld\n", ans); } return 0; }