zoukankan      html  css  js  c++  java
  • Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)

    题目链接

    这个题取模的时候挺坑的!!!

    题意:div(x , b) / mod(x , b) = k( 1 <= k <= a)。求x的和

    分析:

    我们知道mod(x % b)的取值范围为 1  - (b-1)。那么我们可以从这一点入口来进行解题。。

    mod (x, b) = 1 时, x  =  b + 1, 2b + 1, 3b + 1..... a * b + 1.

    mod (x , b) = 2 时, x =  2b + 2, 4b + 2, 6b + 2, ..... 2a * b + 2. = 2(b + 1), 2(2b + 1), 2(3b + 1)...... 2(a * b + 1).

    ....

    mod (x , b) = b - 1..

    可将等式化为:x=k*mod(x,b)*b+mod(x,b).

    枚举1-b-1.  发现每一个式子都是等差数列  可得:ans += (a*(2*i+i*a*b+i*b))/2;  但是会发现  s ab (1 ≤ a, b ≤ 107).

    中间乘起来的时候会超LL,  而且这个式子要对除2, 其实ai*() 这两个乘数里至少有一个偶数,找到并除2就行了。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <queue>
     6 #include <cmath>
     7 #include <algorithm>
     8 #define LL __int64
     9 const int mo = 1e9+7;
    10 const int maxn = 100+10;
    11 using namespace std;
    12 LL a, b;
    13 
    14 int main()
    15 {
    16     LL i;
    17     LL ans;
    18     while(~scanf("%I64d%I64d", &a, &b))
    19     {
    20         ans = 0;
    21         for(i = 1; i < b; i++)
    22         {
    23             if((a*i)%2==0)
    24             {
    25                 LL tmp = (a*i/2)%mo;
    26                 ans += (((2+a*b+b)%mo)*tmp)%mo;
    27                 ans %= mo;
    28             }
    29             else
    30             {
    31                 LL tmp = ((2+a*b+b)/2)%mo;
    32                 ans += ((a*i%mo)*tmp)%mo;
    33                 ans %= mo;
    34             }
    35         }
    36         printf("%I64d
    ", ans);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    js项目结合的注意点
    cookie练习
    json记载字符个数
    js,jQuery获取标签
    新人签到
    使用Resources类搭建Unity简单的资源管理工具类
    初识vue
    原生JS写出贪吃蛇
    用js做一个简单的班级点名器
    Javascript 的"循环语句"
  • 原文地址:https://www.cnblogs.com/bfshm/p/4046582.html
Copyright © 2011-2022 走看看