3502 - 花式作死!
给出一个正整数 n (1 <= n <= 100000000) 试求出点集 {(x, y)|[x] * [y] = n} 在 oxy 平面上的覆盖的面积.
Input
多组数据, 每组数据一行, 包含一个正整数 n.
Output
对于每组输入数据, 输出一行, 表示所求面积, 如果所求面积非整数, 保留三位小数。
Examples
Input
1
Output
2.000
Hint
[x] 表示不超过 x 的最大整数, 例如 [0] = 0, [1.3] = 1, [-2.4] = -3.
Solution C
#include<stdio.h> #include<math.h> int main() { double s; int i,n; while(scanf("%d",&n)!=EOF) { s=0; for(i=1;i<=sqrt(n+0.5);i++) { if(n%i==0&&i!=n/i) s+=2; else if(n%i==0&&i==n/i) s++; } printf("%.3lf\n",s*2); } }
Solution C++
#include <stdio.h> int main () { int n; for (; scanf ("%d", &n) == 1; ) { int res = 0; for (int i = 1; i <= n / i; i++) if (n % i == 0) res += (i * i == n ? 1 : 2); printf ("%d.000\n", res *= 2); } return 0; }
Hint
[x] 表示不超过 x 的最大整数, 例如 [0] = 0, [1.3] = 1, [-2.4] = -3.