这题满满的黑科技orz 题意:给出L,要求求出最小的全部由8组成的数(eg: 8,88,888,8888,88888,.......),且这个数是L的倍数 sol:全部由8组成的数可以这样表示:((10^x)-1)*(8/9) 那么有m=((10^x)-1)*(8/9)=k*L,answer即满足条件的最小的x 性质1:若ax=by且a和b互质,那么说明a中没有任何b的质因子,b的质因子一定都在x里.所以x是b的倍数. 所以先想方设法在等式中构造两个互质的数以便化简.我们取p=8/gcd(8,L…
Burnside引理经典好题呀! 题解参考 https://blog.csdn.net/maxwei_wzj/article/details/73024349#commentBox 这位大佬的. 这题时间卡得很紧,注意矩阵乘法不能太多次取模,不然会TLE.   因为这题的模数是9973,加完之后再取模也不会炸. #include<iostream> #include<cstdio> #include<cmath> #include<cstring> usin…
分析(官方题解): 一点感想: 首先上面那个等式成立,然后就是求枚举gcd算贡献就好了,枚举gcd当时赛场上写了一发O(nlogn)的反演,写完过了样例,想交发现结束了 吐槽自己手速慢,但是发了题解后发现,这题连O(n)欧拉函数前缀和的都卡了,幸亏没交,还是太年轻 对于官方题解说sqrt(n)优化(其实就是n/(小于n一段数)结果是一样的,也不算什么分块),还是很简单的,做反演题的时候看到过很多,只是忘记了 如果不会请看这篇解题报告http://wenku.baidu.com/view/fbe2…
102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB For given integer N (1<=N<=104) find amount of positive numbers not greater than N that coprime with N. Let us call two positive integers (say, A and B, for example) coprime…
题意: 求sum{gcd(i, j) | 1 ≤ i < j ≤ n} 分析: 有这样一个很有用的结论:gcd(x, n) = i的充要条件是gcd(x/i, n/i) = 1,因此满足条件的x有phi(n/i)个,其中Phi为欧拉函数. 所以枚举i和i的倍数n,累加i * phi(n/i)即可. #include <cstdio> typedef long long LL; ; ]; LL f[maxn + ]; void phi_table() { phi[] = ; ; i <…
GCD Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 3   Accepted Submission(s) : 2 Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b…
Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6383   Accepted: 2043 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now…
[bzoj]P2705 OR [luogu]P2303 Longge的问题 Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). Input 一个整数,为N. Output 一个整数,为所求的答案. Sample Input 6 Sample Output 15 HINT [数据范围] 对于60%的数据,0<N<=2^16. 对于100%的数据,0<N<…
Given the value of N, you will have to find the value of G. The definition of G is given below:Here GCD(i, j) means the greatest common divisor of integer i and integer j.For those who have trouble understanding summation notation, the meaning of G i…
Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N.…
题目: Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N. "Oh…
定义 欧拉函数 $\varphi(n)$表示小于等于$n$的正整数中与$n$互质的数的数目. 性质 1.积性函数(证明). 2.$\varphi(1)=1$(显然) 3.对于质数$n$,$\varphi(n)=n-1$(显然) 4.对于质数的幂$n=p^k$(其中$p$为质数,$k$为正整数),$\varphi(n)=p^{k-1}\cdot(p-1)$ 证明: 归纳法,在$k=1$时显然成立,假设当$k$为$k-1$时成立,那么对于将$1,2,...p^k$中每一个数表示为$x\cdot p^…
1615: 刘备闯三国之三顾茅庐(三) Time Limit: 1000 MS  Memory Limit: 128 MBSubmit: 45  Solved: 8[Submit][Status][Web Board] Description 刘备(161年-223年6月10日),字玄德,东汉末年幽州涿郡涿县,西汉中山靖王刘胜的后代.刘备一生极具传奇色彩,早年颠沛流离.备尝艰辛最终却凭借自己的谋略终成一方霸主.那么在那个风云激荡的年代,刘备又是如何从一个卖草鞋的小人物一步一步成为蜀汉的开国皇帝呢…
Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 852 Accepted Submission(s): 259 Problem Descriptionan = X*an-1 + Y and Y mod (X-1) = 0.Your task is to calculate th…
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9231    Accepted Submission(s): 2837 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.   In…
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 3024    Accepted Submission(s): 930 Problem Description M斐波那契数列F[n]是一种整数数列,它的定义如下:F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 )现在给出a, b…
装载自:http://www.cnblogs.com/183zyz/archive/2012/05/11/2495401.html 题目让求一个函数调用了多少次.公式比较好推.f[n] = f[n-1]*f[n-2].然后a和b系数都是呈斐波那契规律增长的.需要先保存下来指数.但是太大了.在这里不能用小费马定理.要用降幂公式取模.(A^x)%C=A^(x%phi(C)+phi(C))%C(x>=phi(C)) Phi[C]表示不大于C的数中与C互质的数的个数,可以用欧拉函数来求. 矩阵快速幂也不…
5152. Brute-force Algorithm EXTREME Problem code: BFALG Please click here to download a PDF version of the contest problems. The problem is problem B in the PDF. But the data limits is slightly modified: 1≤P≤1000000 in the original description, but i…
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 3087    Accepted Submission(s): 953 Problem Description M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a,…
Assume that f(0) = 1 and 0^0=1. f(n) = (n%10)^f(n/10) for all n bigger than zero. Please calculate f(n)%m. (2 ≤ n , m ≤ 10^9, x^y means the y th power of x). InputThe first line contains a single positive integer T. which is the number of test cases.…
欧拉函数 定义 对于正整数n,欧拉函数是小于或等于n的正整数中与n互质的数的数目,记作φ(n). 算法思路 既然求解每个数的欧拉函数,都需要知道他的质因子,而不需要个数 因此,我们只需求出他的质因子,然后根据公式:N*(p1-1)/p1*(p2-1)/p2......即可 #include<bits/stdc++.h> using namespace std; typedef long long ll; ll n; int main() { ll i,j; cin>>n; for(…
题目链接:传送门 思路:欧拉函数的性质:前n个数的欧拉函数之和为φ(n)*n/2,由此求出结果. 参考文章:传送门 #include<iostream> #include<cmath> #include<cstdio> #include<cstring> using namespace std; typedef long long LL; ; LL POW(LL a,LL b) { LL ans=; while(b) { ) ans=ans*a%MOD; a…
小a和小b来到了一条布满了黄金的街道上.它们想要带几块黄金回去,然而这里的城管担心他们拿走的太多,于是要求小a和小b通过做一个游戏来决定最后得到的黄金的数量.游戏规则是这样的:假设道路长度为米(左端点为,右端点为),同时给出一个数(下面会提到的用法)设小a初始时的黄金数量为,小b初始时的黄金数量为小a从出发走向,小b从出发走向,两人的速度均为假设某一时刻(必须为整数)小a的位置为,小b的位置为,若且,那么小a的黄金数量会变为,小b的黄金数量会变为当小a到达时游戏结束小a想知道在游戏结束时的值答案…
P4917 天守阁的地板 题目背景 在下克上异变中,博丽灵梦为了找到异变的源头,一路打到了天守阁 异变主谋鬼人正邪为了迎击,将天守阁反复颠倒过来,而年久失修的天守阁也因此掉下了很多块地板 异变结束后,恢复了正常大小的小碗回到了天守阁,想要修复这里的地板,她需要知道自己要采购的地板数量(一个惊人的数字),于是,她找到了精通oi的你来帮忙 题目描述 为了使万宝槌能发挥出全部魔力,小碗会将买来的地板铺满一个任意边长的正方形(地板有图案,因此不允许旋转,当然,地板不允许重叠)来达到最大共鸣 现在,她能够…
由于这是第一天去实现polya题,所以由易到难,先来个铺垫题(假设读者是看过课件的,不然可能会对有些“显然”的地方会看不懂): 一:POJ1286 Necklace of Beads :有三种颜色,问可以翻转,可以旋转的染色方案数,n<24. 1,n比较小,恶意的揣测出题人很有可能出超级多组数据,所以先打表. 2,考虑旋转: ;i<n;i++) sum+=pow(n,gcd(n,i)); 3,考虑翻转: ) sum+=n*pow(,n/+) ; else { sum+=n/*pow(,n/)…
# 题解 一道数论欧拉函数和欧拉定理的入门好题. 虽然我提交的时候POJ炸掉了,但是在hdu里面A掉了,应该是一样的吧. 首先我们需要求的这个数一定可以表示成\(\frac{(10^x-1)}{9}\times 8\). 那么可以列出一个下面的方程 \[\frac{(10^x-1)}{9}\times 8=L\times k\] 设\(d=gcd(9L,8)=gcd(L,8)\) \[\frac89(10^x-1)=Lk\] \[\frac{8(10^x-1)}d=\frac{9Lk}{d}\]…
这两个题都是项链珠子的染色问题 也是polya定理的最基本和最经典的应用之一 题目大意: 用m种颜色染n个珠子构成的项链,问最终形成的等价类有多少种 项链是一个环.通过旋转或者镜像对称都可以得到置换 旋转可以旋转 i=[1,n]次..画图可以看出循环节有gcd(n,i)个 镜像对称的置换画个图也是很容易找的 然后通过polya定理就可以容易的求出等价类的种数了 2409就是这样一个裸题,以下为ac代码 #include <iostream> #include <stdio.h> #…
/** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include <cstring> using namespace std; #define Max 3000000 ]; ]; ]; void init() { ; memset(flag,,sizeof(flag)); phi[]=; ;i<=Max;i++)//欧拉筛选 { if(flag[i]) {…
欧拉函数 ψ(x)=x*(1-1/pi)  pi为x的质数因子 特殊性质(图片内容就是图片后面的文字) 欧拉函数是积性函数——若m,n互质, ψ(m*n)=ψ(m)*ψ(n): 当n为奇数时,   ψ(2*n)=ψ(n); 若n为质数则                                                                 ψ(n)=n-1; 代码实现求欧拉函数 复杂度O(n*n) (有优化会补上) #include<bits/stdc++.h> #de…
题面: 传送门 思路: 稍微转化一下,可以发现,每个植物到原点连线上植物的数量,等于gcd(x,y)-1,其中xy是植物的横纵坐标 那么我们实际上就是要求2*sigma(gcd(x,y))-n*m了 又有某不知名神奇定理:一个数的所有因子的phi之和等于这个数本身,其中phi是欧拉函数 因此题目转化为求如下: 我们把式子变个型,就成了如下式子: 然后一个前缀和优化,O(n+sqrt(n))解决 Code: #include<iostream> #include<cstdio> #i…