zoukankan      html  css  js  c++  java
  • BZOJ2045 双亲数

    2301的弱化版。。。(弱过头了的说)

    真是。。。为什么2301都1A了这道题却1RE+1A啊。。。蒟蒻到底了。。。

    什么时候搞懂了再写题解什么的。。。

     1 /**************************************************************
     2     Problem: 2045
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:360 ms
     7     Memory:9596 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <cmath>
    12 #include <algorithm>
    13  
    14 using namespace std;
    15 typedef long long ll;
    16 const int N = 1000005;
    17 int u[N], p[N], tot;
    18 bool v[N];
    19  
    20 inline int read(){
    21     int x = 0;
    22     char ch = getchar();
    23     while (ch < '0' || ch > '9')
    24         ch = getchar();
    25          
    26     while (ch >= '0' && ch <= '9'){
    27         x = x * 10 + ch - '0';
    28         ch = getchar();
    29     }
    30     return x;
    31 }
    32  
    33 void pre_work(){
    34     u[1] = 1;
    35     int i, j, K;
    36     for (i = 2; i < N; ++i){
    37         if (!v[i])
    38             p[++tot] = i, u[i] = -1;
    39         for (j = 1; i * p[j] < N && j <= tot; ++j){
    40             v[K = i * p[j]] = 1;
    41             if (i % p[j] == 0){
    42                 u[K] = 0; 
    43                 break;
    44             }else u[K] = -u[i];
    45         }
    46     }
    47     for (i = 2; i < N; ++i)
    48         u[i] += u[i - 1];
    49 }
    50  
    51 ll work(int n, int m, int k){
    52     n /= k, m /= k;
    53     if (n > m) swap(n, m);
    54     ll res = 0;
    55     int i, last;
    56     for (i = 1; i <= n; i = last + 1){
    57         last = min(n / (n / i), m / (m / i));
    58         res += (ll) (u[last] - u[i - 1]) * (n / i) * (m / i);
    59     }
    60     return res;
    61 }
    62  
    63 int main(){
    64     pre_work();
    65     int a = read(), b = read(), k = read();
    66     printf("%lld
    ", work(a, b, k));
    67     return 0;
    68 }
    View Code


     

    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    UltraIso制作U盘启动盘教程
    Windows7下搭建FTP服务器(使用微软)
    Win7中IIS和ASP的安装、配置和使用
    解决ubuntu中vi不能正常使用方向键与退格键的问题
    SQLSERVER的TOP
    VBA读取文件路径中的文件
    博乐园,我来了
    JSON对象,初步认识
    【原创翻译】深入理解CSS盒子模型
    深入浅出CSS3:backgroundclip,backgroundorigin和borderimage教程
  • 原文地址:https://www.cnblogs.com/rausen/p/4049471.html
Copyright © 2011-2022 走看看