QBXT Day 4 数学,数论】的更多相关文章

今天讲一讲数论吧(虽然清明讲过了) 进制转换 我们来看10这个数怎么转换成k进制 因为10=2^3+2^1,所以10就是1010 三进制也同理10=3^2+3^0,所以就是101 我们对于一个10进制数,就可以用短除法来求解 比如55的三进制 这里我们把所有的余数向上写一遍,其实代码实现的话就直接写一个栈就可以了,还有一个没啥用的注意事项,就是读的问题 怎么把一个k进制数转成十进制的X? 假设我们有一个k进制数X,总共有n位,那么他就是XnXn-1Xn-2......X1X0 我们第i位其实就对…
整除性(divisible): 引入了代表整除性. m\n (m|n) 表示m整除n.注意这里的整除.表示的是n = km(k为整数). 在整除性这里.m必须是个正数.也许你可以描述n 是 m 的k倍.这种描述中m完全可以是任何数.而在整除性中的表达m整除n,规定了m必须是个正数.而0没有限制. 那么回答以下问题: 1:什么是0的倍数? 2:什么能被0整除? 3:什么能被-1整除? 4:什么能被1整除? 5:2Pi能被Pi整除吗? 6: 2Pi能被2整除吗? 答案分别是: 1:0 2:没有任何数…
noip一轮复习真的要开始啦!!! 大概顺序是这样的 1.数学 2.搜索贪心 3.数据结构 4.图论 5.dp 6.其他 数学 1.数论 数论被称为数学皇冠上的明珠,他的重要性主要在于它是其他学习的祖师,基本上什么代数问题都可以通过数论推导,其实有的图论也是(数学上). 我们信息中的数论主要是说对整除同余的研究~~~~~~~ ①:唯一分解定理与素数 这个之前我们先要讲素数(定义全部掠过) 素数筛法: #include<iostream> #include<cstdio> #incl…
Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only one integer T, indicates the number of tasks. Then, for the next T lines, each line consists of 6 integers, A , B, C, D, P, n. 1≤T≤200≤A,B,C,D≤1091≤P,…
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gcd(n). Gcd(n)=gcd(C[n][1],C[n][2],--,C[n][n-1]) C[n][k] means the number of way to choose k things from n some things. gcd(a,b) means the greatest common di…
题意: 给定n和k,求 1 ≤ n ≤ 109, 0 ≤ k ≤ 106 思路: 题目中给的提示是对于给定的k我们可以求出一个最高次为k+1的关于n的通项公式. 根据拉格郎日插值法,我们可以通过k+2个离散的点来确定这个通项.所以求出前k+2项,然后就可以确定公式. 拉格郎日差值法传送门:http://www.guokr.com/post/456777/ 最后得出的公式是酱紫的:(公式来自卿学姐博客) 然后问题来了,有除法如何搞定模运算...这个就用到逆元的运算了,逆元的定义就是大家都学过的离散…
1.求逆元 int inv(int a) { ) ; return (MOD - MOD / a) * inv(MOD % a); } 2.线性筛法 bool isPrime[MAXN]; int label[MAXN], prime[MAXN]; int n, total; void makePrime() { n = ; ; i <= n; ++i) { if(!label[i]) { prime[total++] = i; label[i] = total; } ; j < label[…
费马(Fermat)小定理 当 \(p\) 为质数,则 \(a^{p-1}\equiv 1 \mod p\) 反之,费马小定理的逆定理不成立,这样的数叫做伪质数,最小的伪质数是341. 欧拉(Euler)定理 扩展欧拉(Euler)定理 根据扩展欧拉定理,不管a和p是不是互质,都可以缩小到 \([\varphi(p),2\varphi(p)]\) 之间,然后暴力用快速幂求解.…
使用Fermat小定理(Fermat's little theorem)的原理进行测试,不满足 \(2^{n-1}\;\mod\;n\;=\;1\) 的n一定不是质数:如果满足的话则多半是质数,满足上式(通过2为底的Fermat小定理测试)且是合数的,被称为"伪质数"(pseudoprime number),一个简单的伪质数是341.一个合数可能在a=2时通过了测试,但a=3时的计算结果却排除了素数的可能.于是,人们扩展了伪素数的定义,称满足 \(a^{n-1}\;\mod\;n\;=…
终于知道发明者的正确的名字了,是Min_25,这个筛法速度为亚线性的\(O(\frac{n^{\frac{3}{4}}}{\log x})\),用于求解具有下面性质的积性函数的前缀和: 在 \(p\) 处是简单的低次多项式 在 \(p^c\) 处可以快速求值 貌似积性函数是指取一个积性函数 \(f(x)\) ,其在质数的位置上取值与所求函数相同.所以可以用来求n以内的质数的个数(取常函数 \(f(x)=1\) )以及质数的和(取恒等函数 \(f(x)=x\) ). 参考资料: loj#6235.…
[luogu]P1463 [SDOI2005]反素数ant ——!x^n+y^n=z^n 题目描述 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4. 如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例如,整数1,2,4,6等都是反质数. 现在给定一个数N,你能求出不超过N的最大的反质数么? 输入输出格式 输入格式: 一个数N(1<=N<=2,000,000,000). 输出格式: 不超过N的最大的反质数. 输入输出样例 输入样…
题目背景 出题人也想写有趣的题面,可惜并没有能力. 题目描述 给你三个正整数,a,m,ba,m,ba,m,b,你需要求:ab mod ma^b \bmod mabmodm 输入格式 一行三个整数,a,m,ba,m,ba,m,b 输出格式 一个整数表示答案 输入输出样例 输入 #1 复制 2 7 4 输出 #1 复制 2 输入 #2 复制 998244353 12345 98765472103312450233333333333 输出 #2 复制 5333 说明/提示 注意输入格式,a,m,ba,…
思路统计最大值出现的次数,和最小值出现的次数.虽然是每次都是MAX-MIN,我们先求MAX的和,然后再求MIN的和,做差. 这次代码写的真的很漂亮 题目地址: #include <bits/stdc++.h> using namespace std; template <typename t> void read(t &x) { char ch = getchar(); x = 0; t f = 1; while (ch < '0' || ch > '9') f…
I will show you the most popular board game in the Shanghai Ingress Resistance Team. It all started several months ago. We found out the home address of the enlightened agent Icount2three and decided to draw him out. Millions of missiles were detonat…
Description 给出一个区间[L,R][L,R],问该区间中所有以KK作为最小因子(大于11的)的数字之和 Input 第一行输入一整数TT表示用例组数,每组用例输入三个整数L,R,KL,R,K(1≤L≤R≤1011,2≤K≤1011)(1≤L≤R≤1011,2≤K≤1011) Output 对于每组用例,输出答案,结果模109+7109+7 Sample Input 2 1 20 5 2 6 3 Sample Output Case #1: 5 Case #2: 3 先放网上的通解,就…
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either…
Problem Description Everybody knows any number can be combined by the prime number. Now, your task is telling me what position of the largest prime factor. The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc. Specially, LPF(1) = 0. Inpu…
Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1<=N<=10^9). The input is terminated by a set starting with N = 0. This set should not be processed. Output For each test case, output on a line the v…
Problem Description people in USSS love math very much, and there is a famous math problem give you two integers n,a,you are required to find 2 integers b,c such that an+bn=cn. Input one line contains one integer T;(1≤T≤1000000) next T lines contains…
先说勾股数: 勾股数,又名毕氏三元数 .勾股数就是可以构成一个直角三角形三边的一组正整数.勾股定理:直角三角形两条直角边a.b的平方和等于斜边c的平方(a²+b²=c²) 勾股数规律: 首先是奇数组口诀:平方后拆成连续两个数. 其次是偶数组口诀:平方的一半再拆成差2的两个数. 我们深挖一下口诀 定理: 如a2+b2=c^2是直角三角形的三个整数边长,则必有如下a值的奇数列.偶数列关系成立: 1.直角三角形a2+b2=c2a^2+b^2=c^2a2+b2=c2奇数列a法则: 若a表为2n+1型奇数…
Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" 人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下: 数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2,3,4,6. 你想知道你的另一半吗? Input 输入数据的第一行是一个数字T(1<=T<=500000),它表明测试数据的组数.然后是T组测试数据,每组测试数据…
Description Everybody in the Prime Land is using a prime base number system. In this system, each positive integer x is represented as follows: Let {pi}i=0,1,2,... denote the increasing sequence of all prime numbers. We know that x > 1 can be represe…
P4718 [模板]Pollard-Rho算法 题目描述 MillerRabin算法是一种高效的质数判断方法.虽然是一种不确定的质数判断法,但是在选择多种底数的情况下,正确率是可以接受的.PollardRho是一个非常玄学的方式,用于在O(n1/4)的期望时间复杂度内计算合数n的某个非平凡因子.事实上算法导论给出的是O(p),p是n的某个最小因子,满足pp与n/pn/p互质.但是这些都是期望,未必符合实际.但事实上PollardRho算法在实际环境中运行的相当不错.这里我们要写一个程序,对于每个…
ACM常用模板合集 #include <bits/stdc++.h> using namespace std; typedef long long ll; ll pr; ll pmod(ll a, ll b, ll p) { return (a * b - (ll)((long double)a / p * b) * p + p) % p; } //普通的快速乘会T ll gmod(ll a, ll b, ll p) { ll res = 1; while (b) { if (b &…
RhoPollard Rho是一个著名的大数质因数分解算法,它的实现基于一个神奇的算法:MillerRabinMillerRabin素数测试. 操作流程 首先,我们先用MillerRabinMillerRabin判断当前数xx是否为质数,若是,则可直接统计信息并退出函数 然后是各种证明及优化,我觉得不大实用,这个板子是我改了很多遍了,也过了很多题的板子.用着很舒服,无论卡常,不卡常,速度相差不大,也可以加read. #include <bits/stdc++.h> using namespac…
Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y+zn=x+y+z, x∣nx∣n, y∣ny∣n, z∣nz∣n and xyzxyz is maximum. Input There are multiple test cases. The first line of input contains an integer TT (1≤T≤1061…
Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y+zn=x+y+z, x∣nx∣n, y∣ny∣n, z∣nz∣n and xyzxyz is maximum. Input There are multiple test cases. The first line of input contains an integer TT (1≤T≤1061…
In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n that are relatively prime to n. It can be defined more formally as the number of integers k in the range 1≤k≤n for which the greatest common divisor…
I will show you the most popular board game in the Shanghai Ingress Resistance Team. It all started several months ago. We found out the home address of the enlightened agent Icount2three and decided to draw him out. Millions of missiles were detonat…
Problem Description When Teddy was a child , he was always thinking about some simple math problems ,such as "What it's 1 cup of water plus 1 pile of dough .." , "100 yuan buy 100 pig" .etc.. One day Teddy met a old man in his dream ,…