同余问题 基本定理: 若a,b,c,d是整数,m是正整数, a = b(mod m), c = d(mod m) a+c = b+c(mod m) ac = bc(mod m) ax+cy = bx+dy(mod m) -同余式可以相加 ac = bd(mod m) -同余式可以相乘 a^n = b^n(mod m) f(a) = f(b)(mod m) if a = b(mod m) and d|m then a = b(mod d) eg: 320 = 20(mod 100) and d =…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1104 在做这道题目一定要对同余定理有足够的了解,所以对这道题目对同余定理进行总结 首先要明白计算机里的取余计算和数学里的不一样的,计算机里的负数取余可以是负数的.例如-1%11=-1 而数学里的取余是-1%11=10 同余定理: 若a对d取余,和b对d取余的结果是相等的,那么称a,b对d是同余的.记作a≡b(mod d);这是数学里的定义. 下面看同余定理的几个性质: 1,a≡a(mod d) 数字…
此题往后推几步就可找到规律,从1开始,答案分别是1,2,4,8,16.... 这样就可以知道,题目的目的是求2^n%Mod的结果.....此时想,应该会想到快速幂...然后接着会发现,由于n的值过大,很容易就会T掉... 所以这个时候就想到找规律...试试就可以知道,1e9+6的时候是循环节... 然后用同余定理,把余数求出来就可以了... #include<iostream> #include<string> #include<string.h> #include&l…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B.To make the problem easier, I…
下午做了NYOJ-424Eddy's digital Roots后才正式接触了九余定理,不过这题可不是用的九余定理做的.网上的博客千篇一律,所以本篇就不发篇幅过多介绍九余定理了: 但还是要知道什么是九余定理: 九余数定理 一个数对九取余后的结果称为九余数. 一个数的各位数字之和相加后得到的<10的数字称为这个数的九余数(如果相加结果大于9,则继续各位相加) 简单的说就是:一个整数模9的结果与这个整数的各位数字之和模9的结果相同: 以前做题不知道有这个定理一般暴力就过了,求数位和也不复杂,只不过更…
题目如下: Description 请求N!(N<=10000),输出结果对10007取余输入每行一个整数n,遇到-1结束.输出每行一个整数,为对应n的运算结果.   Sample Input 1 2 -1   Sample Output 1 2 分析思路: 题目思路很简单,每读取一个输入就输出对应输入的阶乘.直到遇到输入为-1时结束程序. 核心问题: 这个题目在写的时候遇到的难点是N!实在是太大了,根本储存不下,之后试了long long int 也还是只能储存到20几就会溢出.解决这个问题的…
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an integer a is divisible by an integer b if and only if there exists an integer c such that a = b * c. Input Input starts with an integer T (≤ 525), denot…
The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15767   Accepted: 4337 Description The young and very promising cryptographer Odd Even has implemented the security module of a large system with thousands of…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1214 题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0.而A很大,那我就把A的每一位拆开,比如A是2341,那么2341=2000+300+40+1,然后你懂的... #include <iostream> #include <cstdio> #include <cstring> using namespace std; ]; int mai…
Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5930    Accepted Submission(s): 4146 Problem Description As we know, Big Number is always troublesome. But it's really important in our…
The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   Accepted: 3194 Description The young and very promising cryptographer Odd Even has implemented the security module of a large system with thousands of…
思路:d(i,j)表示以i开头,长度为j的K好数的个数,转移方程就是 for(int u = 0; u < k; ++u) { int x = abs(i - u); if(x == 1) continue; //相邻的数字相同 dp[i][j] += dp[u][j-1]; } 还有就是可能答案很大一定要一边求解一边求余. 同余定理用起来,内存可用滚动数组优化. AC代码 #include <cstdio> #include <cmath> #include <alg…
BUPT2017 wintertraining(16) #5 A HDU - 1021 题意 There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2). 输入n,若F(n)能被3整除,输出yes,否则no 题解 列一下前几项F(i)可以发现n%4==2则是yes,否则no. 代码 #include <cstdio> #include <cstring…
青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:132162   Accepted: 29199 Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置.不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能…
A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10383    Accepted Submission(s): 8302 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1).   Input 数据的第一行是…
Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4594    Accepted Submission(s): 3175 Problem Description As we know, Big Number is always troublesome. But it's really important in ou…
id=1465">http://poj.org/problem?id=1465 Multiple Time Limit: 1000MS   Memory Limit: 32768K Total Submissions: 6164   Accepted: 1339 Description a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digit…
D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output Nick is attracted by everything unconventional. He doesn't like decimal number system any more, and he decided to study other numb…
J - Judge   Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Status Practice HPU 1194 Description Ocean从影视城回来后,吃了一个放大果实(恶魔果实的一种),高呼:“海贼王に.俺はなる!” Ocean每使用一次能力,就可以将一个物品的价值放大$x$倍(原价值乘以$x$). 但是哪有这么好的事情? 物品的价值是有限度的,姑且认为物品…
Description Edward  得到了一个长度为  N  的整数序列,他想找出这里面有多少个“幸运的”连续子序列.一个连续子序列被称为“幸运的”,当且仅当该子序列内的整数之和恰好是  K  的整数倍数.他请求你写一个程序来计算他喜欢的连续子序列个数. Input 输入第一行是一个整数  T,表示有  T  组数据.每组数据第一行是两个整数  N (1 <= N <= 10^6), K (1 <= K <= 10^9).接下来的一行包含  N  个整数  Ai (|Ai| &…
1433 0和5 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5.小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数.使得这个数尽可能大,而且可以被90整除. 注意: 1.这个数没有前导0, 2.小K不需要使用所有的牌. Input 每个测试数据输入共2行. 第一行给出一个n,表示n张牌.(1<=n<=1000) 第二行给出n个…
2016湖南省赛----A 2016 (同余定理) Description  给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数据. 每组数据包含两个整数 n,m (1≤n,m≤10 9). Output 对于每组数据,输出一个整数表示满足条件的数量. Sample Input 32 63 2016 2016 1000000000 1000000000 Sample…
题意: 给你一个n和一个数 digit ,问你最少需要多少个 digit 使得整除于n; 思路: 同余定理(a+b)%n=(a%n+b%n)%n; (m%n+m%n*10+m%n*100+m%n*1000......)%n==0; temp=m%n; temp=(temp*10+m)%n=(10*m%n+m%n)%n; temp=(temp*10+m)%n=(10*10*m%n+10*m%n+m)%n; if(temp==0) 满足: #include <bits/stdc++.h> usin…
A sequence of numbers                                                             Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                                                                    …
题目地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 Knowledge Point: 同余定理:两个整数a.b,若它们除以整数m所得的余数相等,则称a与b对模m同余或a同余于b模m.记作 a≡b(mod m): 加法运用: (a + b) % m = (a % m + b % m) % m 乘法运用: (a * b) % m = ((a % m) * (b % m)) % m 高精度取模: 一个高精度数对一个数取余,可以把高精…
题目意思: 给定a和n,计算a+aa+aaa+aaaa+...+a...a(n个a) 的和. 输入描写叙述:測试数据有多组,以文件结尾.每行输入a,n(1<=a,n<=1000000). 输出描写叙述:因为结果可能比較大,所以请输出答案mod 1000000007. http://student.csdn.net/mcs/programming_challenges 题目分析: 同余定理: s=0; abc&MOD=((a*10%MOD+b%MOD)*10%MOD+c%MOD)%MOD…
2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理 [Problem Description] \[ 求解x^{2^{30}+3}=c\pmod n \] 其中\(n=p\cdot q\),\(p\)为小于\(x\)的最大素数,\(q\)为大于\(x\)的最小素数,\(x\)为\([10^5,10^9]\)内随机选择的数.\(0< c<n\).…
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 2004^1 are 1, 2, 3,…
Problem Statement There are NN buildings along the AtCoder Street, numbered 11 through NN from west to east. Initially, Buildings 1,2,-,N1,2,-,N have the heights of A1,A2,-,ANA1,A2,-,AN, respectively. Takahashi, the president of ARC Wrecker, Inc., pl…
最近正在学AC自动机,按照惯例需要刷一套kuangbin的AC自动机专题巩固 在网上看过很多模板,感觉kuangbin大神的模板最为简洁,于是就选择了用kuangbin大神的模板. AC自动机其实就是字典树和KMP的结合,然后去思考一下KMP的原理,然后就是在字典树上实现KMP 这里最重要的思想可能就是fail的思想,就像KMP一样,匹配失败后,有一个next的数组去回溯(最长公共前缀后缀) 如何理解了KMP的话,感觉这个不会很难理解,字典树是一个非常简单的东西就不用讲了吧. HDU - 222…