zoukankan      html  css  js  c++  java
  • XidianOJ 1182 Chinese Paladin – Qi’s troubles

    题目描述

    As we all know, Xiahou Jinxuan (Chinese Paladin 5 Prequel’s protagonist) and Yue Jinzhao 

    (Chinese Paladin 6’s protagonist) are the most intelligent in Legend series. But who is more NB? 

    However,it's not enough that only themselves are NB ,they believe that who's wife is more

     intelligent,who is more NB.
    So they ask their wives to compete. In this case, Xia (Xiahou Jinxuan 's wife) said to Qi

     (Yue Jinzhao 's wife) , "Well, I have a problem, if you can answer it, I will admit that your husband is more NB than my husband." Xia is confident, because Qi is only three years old (why is Qi too 

    young but has a husband, please play Chinese Paladin 6), even if she is a genius, she certainly can't answer it.
    Here is the problem: Give you a number n, then constructed a number sequence as following : n, n + 1, n + 2,n + 1, n + 2, n + 3, n + 2, n + 3, n + 4 ... 
    calculate the sum of the first m items of this number sequence , and outputs the result mod 23333333333, 1 <= n, m <= 10 ^ 12.
    Please help Qi to solve the problem, Qi doesn’t want to make Jinzhao ashamed ~

    输入

    Multiple test cases, please read until EOF

    For each test case: One line contains two single integer n, m separated by space

    (1 <= n, m <= 10 ^ 12)

    输出

     For each test case:

    One line contains a single integer, the answer.

    --正文

    前面大段废话,我特意去查了Chinese Paladin,竟然是仙剑www

    其实就是三个一循环,很容易找到式子来计算

    主要大数的乘法

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #define MOD 23333333333
    using namespace std;
    typedef long long LL;
    LL n,m;
    
    
    LL big_multi(LL a,LL b){
        LL ans = 0;
        a = a % MOD;
        while (b){
            if (b & 1) ans = (ans + a) % MOD;
            b = b >> 1;
            a = (a + a) % MOD;
        }
        return ans;
    } 
    
    int main(){
        while (scanf("%lld %lld",&n,&m) != EOF){
            LL m3 = m/3;
            LL mmod3 = m%3; 
            LL res;
            if (m3 % 2 == 0)
                res = (big_multi(n,m) + big_multi(3*m3/2,m3+1)) % MOD;
            else 
                res = (big_multi(n,m) + big_multi(3*m3,(m3+1)/2)) % MOD;
            if (mmod3 == 1){
                res = (res + m3) % MOD; 
            }
            if (mmod3 == 2){
                res = (res + m3 + m3 + 1) % MOD;
            }
            printf("%lld
    ",res);
        }
        return 0;
    }
  • 相关阅读:
    dinic模板
    匈牙利算法(codevs2776)
    线段树(codevs1082)
    KM模板
    kmp模板,线性完成pos
    (一)Python入门-2编程基本概念:03引用的本质-栈内存和堆内存-内存示意图
    (一)Python入门-2编程基本概念:04标识符-帮助系统简单实用-命名规则
    (一)Python入门-2编程基本概念:05变量的声明-初始化-删除变量-垃圾回收机制
    (一)Python入门-2编程基本概念:06链式赋值-系列解包赋值-常量
    (一)Python入门:05Python程序格式-缩进-行注释-段注释
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6155521.html
Copyright © 2011-2022 走看看