zsy姐姐的NH-3:關於浮點數精度問題的一些研究
阿新 • • 發佈:2022-03-11
模板:P1403 [AHOI2005]約數研究 - 洛谷 | 電腦科學教育新生態 (luogu.com.cn)
1 #include "bits/stdc++.h" 2 #define PII pair<int,int> 3 #define rep(i,z,n) for(int i = z;i <= n; i++) 4 #define per(i,n,z) for(int i = n;i >= z; i--) 5 #define ll long long 6 #define db double 7 #define vi vector<int> 8 #definedebug(x) cerr << "!!!" << x << endl; 9 using namespace std; 10 //從某個串中把某個子串替換成另一個子串 11 string& replace_all(string& src, const string& old_value, const string& new_value) { 12 // 每次重新定位起始位置,防止上輪替換後的字串形成新的old_value 13 for (string::size_type pos(0); pos != string::npos; pos += new_value.length()) {14 if ((pos = src.find(old_value, pos)) != string::npos) { 15 src.replace(pos, old_value.length(), new_value); 16 } 17 else break; 18 } 19 return src; 20 } 21 inline ll read() 22 { 23 ll s,r; 24 r = 1; 25 s = 0; 26 char ch = getchar(); 27 while(ch < '0' || ch > '9'){ 28 if(ch == '-') 29 r = -1; 30 ch = getchar(); 31 } 32 while(ch >= '0' && ch <= '9'){ 33 s = (s << 1) + (s << 3) + (ch ^ 48); 34 ch = getchar(); 35 } 36 return s * r; 37 } 38 inline void write(ll x) 39 { 40 if(x < 0) putchar('-'),x = -x; 41 if(x > 9) write(x / 10); 42 putchar(x % 10 + '0'); 43 } 44 int main() 45 { 46 int n; 47 n = read(); 48 int nex = 1; 49 int bnd; 50 int ans = 0; 51 int res; 52 rep(i,1,n){ 53 res = n / nex; 54 if(res)//防止除0 55 bnd = n / res; 56 ans += res * (bnd - nex + 1);//為res的除數一共有bnd - nex + 1個 57 nex = bnd + 1; 58 } 59 cout << ans; 60 return 0; 61 }