God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous. Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 3 c…
首先矩阵快速幂可以算出来第k项的指数,然后可以利用原根的性质,用bsgs和exgcd把答案解出来 #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e2 + 10; const ll Mod = 998244353; ll add(ll a, ll b, ll mod = Mod) { return (a += b) >= mod ? a - mod : a; } ll sub…
题目链接: Reading comprehension Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Read the program below carefully then answer the question.#pragma comment(linker, "/STACK:1024000000,1024000000&quo…
Codeforces 963 A. Alternating Sum 题目大意:给出一组长度为n+1且元素为1或者-1的数组S(0~n),数组每k个元素为一周期,保证n+1可以被k整除.给a和b,求对1e9+9取模的结果 思路:容易想到,每个周期的∑组成的数列成等比,公比q=(b/a)^k,因此可以用等比数列公式求和.为了保证时间复杂度,需要用到快速幂运算:为了防止中间过程值溢出,需要多处取模,其中用费马小定理求逆元: 代码: #include<iostream> #include<cst…
题目:给定n*n的矩阵A,求A^k. 解法:利用矩阵乘法的定义和快速幂解答.注意用负数,但是数据太弱没有卡到我......(P.S.不要在 typedef long long LL; 前使用 LL......━━( ̄ー ̄*|||━━) P.S.在multi函数里,若将所有相乘的和先加起来不会爆 long long ,那就最后再模会快不少. 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #inc…
题目链接: All X Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description F(x,m) 代表一个全是由数字x组成的m位数字.请计算,以下式子是否成立: F(x,m) mod k ≡ c Input 第一行一个整数T,表示T组数据.每组测试数据占一行,包含四个数字x,m,k,c 1≤x≤9 1≤m≤10^10 0≤c<k≤10,…
Happy 2004 问题描述 : Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to determine S modulo 29 (the rest of the division of S by 29). Take X = 1 for an example. The positive integer divisors of 2…
题目描述 输入b,p,k的值,求b^p mod k的值.其中b,p,k*k为长整型数. 输入输出格式 输入格式: 三个整数b,p,k. 输出格式: 输出“b^p mod k=s” s为运算结果 作为初学者,还是应当用简洁的方法和代码(我认为很简洁),废话不说,直接看代码: #include<iostream> #include<cstdio> #include<cmath> using namespace std; long long x(long long int a…
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 865 Accepted Submission(s): 534 Problem Description There are an equation.∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?We define…
题目地址:https://www.nowcoder.com/acm/contest/136/F 树状数组.快速幂.逆元的模板运用: #include<iostream> #include<cstdio> using namespace std; #define LL long long #define lowbit(x) x&-x ; ; int n, m; LL sum[N]; void read(int &x) { ; x = ; char ch = getch…
It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: since every 3 or more persons could make a chat group, there can be 42 different chat groups. Given N persons in a dormitory, and every K or more per…
瞬间移动 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2121 Accepted Submission(s): 949 Problem Description 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第n行第m列的格子有几…