• bzoj 1257: [CQOI2007]余数之和sum


    这是个神题233(一开始想的也差不多,然而不知道为什么觉得复杂度不对,(没想到等差数列,就GG掉了))

    一个数k,k/x=y...?,?构成等差数列,直接o(1)解决,每得出一个y的区间,是[i,last](last见程序,至于为什么,写写看看,挺显然的)

     1 #include<bits/stdc++.h>
     2 #define N 100005
     3 #define LL long long
     4 #define inf 0x3f3f3f3f
     5 #define ls tr[x][0]
     6 #define rs tr[x][1]
     7 using namespace std;
     8 inline int ra()
     9 {
    10     int x=0,f=1; char ch=getchar();
    11     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    12     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    13     return x*f;
    14 }
    15 int main()
    16 {
    17     int n=ra(),k=ra();
    18     int last,lmt=min(n,k),d;
    19     LL tem,ans=0;
    20     if (n>k) ans=(LL)k*(n-k);
    21     for (int i=1; i<=lmt; i=last+1)
    22     {
    23         d=k/i;
    24         last=min(k/d,lmt);
    25         tem=last-i+1;
    26         ans+=tem*(k%i)-(tem*(tem-1)>>1)*d;
    27     }
    28     cout<<ans;
    29     return 0;
    30     
    31 }
  • 相关阅读:
    手机抓包方法
    IBM appscan 9.0破解版分享
    C#打开新页面
    双城记
    卸载趋势
    测试环境搭建
    C#常用函数→ASP.NET篇
    C#常用函数--通用篇
    读>>>>白帽子讲Web安全<<<<摘要→我推荐的一本书→1
    TCP/IP网络编程技术基础
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6392057.html
Copyright © 2020-2023  润新知