リンク:
https://vjudge.net/problem/LightOJ-1245
質問の意味:
私はこの問題を解決するには「1234 - ハーモニック・ナンバー」しようとしていた、私は次のコードを書きました
長い長H(INT N){
長い長いRES = 0。
以下のために(INT I 1 =; I <= N; I ++)
RES = RES + N / I。
解像度を返します。
}
はい、私のエラーは、私が唯一の整数の分割を使用していたということでした。ただし、nは与えられている、あなたは私のコードのようにH(n)を見つける必要があります。
アイデア:
考察は整数を限定N / I、下限値)をN /(N / I)の最大値です。群れの値に等しい連続サイクルは、タイムアウトをスキップしません。
コード:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 1e7+10;
const int MOD = 1e9+7;
LL n;
int main()
{
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cnt);
scanf("%lld", &n);
LL p = 1;
LL sum = 0;
while(p <= n)
{
LL tmp = n/p;
LL next = n/(n/p);
sum += 1LL*tmp*(next-p+1);
p = next+1;
}
printf(" %lld\n", sum);
}
return 0;
}