Submission #27754365
Source Code Expand
/*
Author: Nguyen Tan Bao
Status:
Idea:
*/
#include <bits/stdc++.h>
#define FI first
#define SE second
#define ALL(a) a.begin(), a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define TRAV(x, a) for (auto &x : a)
using namespace std;
using ll = long long; using ld = double;
using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>;
using cd = complex<ld>; using vcd = vector<cd>;
using vi = vector<int>; using vl = vector<ll>;
using vd = vector<ld>; using vs = vector<string>;
using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; // vector<pair>
template<class T> using min_pq = priority_queue<T, vector<T>, greater<T> >;
template<class T> inline int ckmin(T& a, const T& val) { return val < a ? a = val, 1 : 0; }
template<class T> inline int ckmax(T& a, const T& val) { return a < val ? a = val, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sort(ALL(v)); v.erase(unique(ALL(v)), end(v)); }
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
ll ceilDiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
ll floorDiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down
void setPrec(int x) { cout << fixed << setprecision(x); }
// TO_STRING
#define ts to_string
string ts(char c) { return string(1, c); }
string ts(const char* s) { return (string) s; }
string ts(string s) { return s; }
string ts(bool b) { return ts((int)b); }
template<class T> string ts(complex<T> c) { stringstream ss; ss << c; return ss.str(); }
template<class T> using V = vector<T>;
string ts(V<bool> v) {string res = "{"; FOR(i,0,SZ(v)-1) res += char('0'+v[i]); res += "}"; return res; }
template<size_t sz> string ts(bitset<sz> b) { string res = ""; FOR(i,0,SZ(b)-1) res += char('0'+b[i]); return res; }
template<class T, class U> string ts(pair<T,U> p);
template<class T> string ts(T v) { // containers with begin(), end()
bool fst = 1; string res = "";
for (const auto& x: v) { if (!fst) res += " "; fst = 0; res += ts(x); }
return res;
}
template<class T, class U> string ts(pair<T,U> p) { return "("+ts(p.FI)+", "+ts(p.SE)+")"; }
// OUTPUT
template<class T> void pr(T x) { cout << ts(x); }
template<class T, class ...U> void pr(const T& t, const U&... u) { pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
template<class T, class ...U> void ps(const T& t, const U&... u) { pr(t); if (sizeof...(u)) pr(" "); ps(u...); }
// DEBUG
void DBG() { cerr << "]" << endl; }
template<class T, class ...U> void DBG(const T& t, const U&... u) { cerr << ts(t); if (sizeof...(u)) cerr << ", "; DBG(u...); }
#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
<< __FUNCTION__ << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
const ld PI = acos(-1.0);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const ld EPS = 1e-9;
const ll MODBASE = 1000000007LL;
const int INF = 0x3f3f3f3f;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
ll n;
cin >> n;
int x = int(sqrt(n));
ll res = 0;
FOR(i,1,x) {
res += n / i;
}
// x+1 -> n
for (ll w = n / (x+1); w >= 1; w--) {
ll g = n / w;
ll h = n / (w + 1);
ll diff = g - h;
res += diff * w;
}
cout << res;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - Fraction Floor Sum |
| User |
farmerboy |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
4063 Byte |
| Status |
AC |
| Exec Time |
36 ms |
| Memory |
3688 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt, example_01.txt |
| All |
example_00.txt, example_01.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
5 ms |
3584 KiB |
| example_01.txt |
AC |
7 ms |
3688 KiB |
| random_00.txt |
AC |
35 ms |
3584 KiB |
| random_01.txt |
AC |
33 ms |
3504 KiB |
| random_02.txt |
AC |
34 ms |
3616 KiB |
| random_03.txt |
AC |
3 ms |
3484 KiB |
| random_04.txt |
AC |
2 ms |
3544 KiB |
| random_05.txt |
AC |
2 ms |
3480 KiB |
| random_06.txt |
AC |
22 ms |
3584 KiB |
| random_07.txt |
AC |
19 ms |
3552 KiB |
| random_08.txt |
AC |
17 ms |
3612 KiB |
| random_09.txt |
AC |
25 ms |
3608 KiB |
| random_10.txt |
AC |
35 ms |
3604 KiB |
| random_11.txt |
AC |
33 ms |
3548 KiB |
| random_12.txt |
AC |
27 ms |
3552 KiB |
| random_13.txt |
AC |
28 ms |
3476 KiB |
| random_14.txt |
AC |
32 ms |
3612 KiB |
| random_15.txt |
AC |
33 ms |
3508 KiB |
| random_16.txt |
AC |
28 ms |
3588 KiB |
| random_17.txt |
AC |
31 ms |
3556 KiB |
| random_18.txt |
AC |
34 ms |
3608 KiB |
| random_19.txt |
AC |
36 ms |
3532 KiB |