题目描述
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\n",res); } return 0; }