
数学number_theory
文章平均质量分 58
incredible_bly
这个作者很懒,什么都没留下…
展开
-
数学专项number_theory:UVa 10622
刚开始想直接用库函数直接水过,结果发现居然还会有负数。然后就想到因式分解,统计每个质因子的数量,求出这些数量的gcd即可。当n为负数时,结果不能为偶,需要把结果中的因子2除净。#include #include #include #include using namespace std;const int M=1000010;int n,c;int vis[M];int pri原创 2013-04-24 19:06:26 · 610 阅读 · 0 评论 -
数学专项number_theory:UVa 756
注意到23,28,33互质,所以可以通过中国剩余定理很容易的求解。#include #include using namespace std;const int period=21252;const int m[3]={23,28,33};int p[3],D;void gcd(int a,int b,int& d,int& x,int& y){ if(!b){d=a;x原创 2013-06-27 23:41:08 · 603 阅读 · 0 评论 -
数学专项number_theory:UVa 718
很容易判断哪些电梯可以到达A,哪些电梯可以到到B。然后两两判断电梯是否可以在某一层相连,即建个图。这里就需要解一个具有两个方程的模方程组了。这里,我分了两种情况。首先是当两者的X互质,即模互质时可以直接用中国剩余定理。而当两者不互质时,则采用枚举的方法。最后再以可以到达A的电梯进行dfs就行了。只不过还是很慢,近1s,估计是想复杂了……#include #include #incl原创 2013-06-28 21:56:57 · 717 阅读 · 0 评论 -
数学专项number_theory:LA 4079
学过复变函数的都知道,复数可以由模乘上辐角来表示。所以不难得出当a*a+2*b*b为素数时,该数为高斯素数。但是还得考虑a或b为0的情况,这里我用了枚举的方法,若a或b能表示为x*x+2*y*y的形式且为为素数时,该数也为高斯素数。#include #include #include #include using namespace std;int isprime(int x){原创 2013-06-30 23:03:06 · 1239 阅读 · 3 评论 -
数学专项number_theory:UVa 10162
不难发现每十个数的和的个位数为7,这样结果就只与数的最后两位有关了。然后,个位数对结果的影响以十位数的奇偶分两种情况。这样,结果就出来了。#include #include #include using namespace std;int a1[]={0,1,5,2,8,3,9,2,8,7};int a2[]={0,1,7,0,6,1,7,4,8,7};int main(){原创 2013-06-29 22:31:25 · 645 阅读 · 0 评论 -
数学专项number_theory:LA 2955
一道关于梅森素数的题,这里需要先得出一个猜想,那就是只有梅森素数的一次幂的乘积的因子之和才能为2的次幂。这个猜想我不会证明,我只是测了下前100个素数,然后就觉得这个猜想应该是正确的,结果也确实如此。(求数学帝证明)2^31内仅有8个梅森素数,只要将每个Pi因式分解,直接剔除那些既不是梅森素数,也不是梅森素数乘积的数,注意梅森素数的幂次不能超过1,所以必须选择剩下的可行的数的组合使得到的2的幂原创 2013-07-21 23:23:06 · 671 阅读 · 0 评论 -
数学专项number_theory:UVa 11768
这道题之前做过一次,在WA了数炮之后,就把这题放下了。这几天找了本《数论概论》稍稍系统的学了下,今天把这题重新找了出来做一做。结果从下午3点做到晚上9点,自己手写了数据生成器和一个暴力的程序,一步一步调才把这题给AC了,实在太不容易了。回过头来看似乎也不算太难,只不过有相当多需要注意的地方。首先将直线化成一般式,然后把所有参数都处理成整数即a*x+b*y=c的形式,然后用扩展gcd求出一个原创 2013-07-19 23:53:41 · 1017 阅读 · 3 评论 -
数学专项number_theory:LA 3521
就是要计算sum{k%i|1k的情况很容易处理。所以只要可以快速计算出sum{k%i|1#include #include #include #include #include using namespace std;typedef long long LL;LL n,k,m;int main(){ while(scanf("%lld%lld",&n,&k)!=E原创 2013-10-24 10:21:58 · 736 阅读 · 0 评论 -
数学专项number_theory:LA 4382
利用wilson’s theorem可知所求的就是sum{[3*k+7为素数]|1#include #include #include using namespace std;const int maxn=5000010;int vis[maxn];int cnt[maxn];void init(){ memset(vis,0,sizeof(vis)); m原创 2013-10-28 16:40:06 · 661 阅读 · 0 评论 -
数学专项number_theory:LA 3262
题意就是找出n(1这里需要自己手写一个高精度类以比较大数,先枚举一个数的情况,若不存在,再枚举二个数的情况即可。#include #include #include #include using namespace std;const int maxn=66000;struct bign{ int len,s[maxn]; bign(){memset(s,原创 2013-10-22 12:25:41 · 529 阅读 · 0 评论 -
数学专项number_theory:UVa 10368
不难发现每次减的策略只有两种,要么将较大的数对较小的数求余,或者求余之后再加上加上较小的数。如果用dfs暴力搜的话,其递归深度为欧几里得算法的时间复杂度,即较小数的对数,完全可以接受。结果跑了19ms。#include #include #include using namespace std;int a,b;int dfs(int a,int b){ if(a<b) sw原创 2013-06-28 22:53:06 · 698 阅读 · 0 评论 -
数学专项number_theory:UVa 294
就是枚举L与U之间的数,然后因式分解,divisor的数量即为其质因子按其阶数+1的乘积。#include #include #include using namespace std;int a,b,c;int prime[100000];int vis[1000100];void init(){ memset(vis,0,sizeof(vis)); for(i原创 2013-06-28 22:42:32 · 657 阅读 · 0 评论 -
数学专项number_theory:UVa 10127
用简单的模运算从长度为1开始枚举即可。#include #include using namespace std;int n;int solve(){ int v=1; int cnt=1; while(v) { v=(long long)(v*10+1)%n; cnt++; } return cnt;原创 2013-04-26 22:12:04 · 607 阅读 · 0 评论 -
数学专项number_theory:UVa 10090
额,这道数论题做的异常之蠢……我还傻乎乎的去解了下模方程--#。后来看题解才知道,直接用扩展的gcd就可以做。还是贴一下我丑陋的代码吧……#include #include using namespace std;typedef long long LL;void gcd(LL a,LL b,LL& d,LL& x,LL& y){ if(!b) {d=a;x=1;y=0;}原创 2013-04-27 21:13:03 · 581 阅读 · 0 评论 -
数学专项number_theory:UVa 10515
枚举m的最后一位,找到规律就很容易做了。这道题的数据不是很强,m、n都没有前导0,不然的话就得用高精度了。#include #include #include using namespace std;string n,m;int main(){ freopen("in.txt","r",stdin); while(cin>>m>>n) { i原创 2013-04-19 22:34:38 · 633 阅读 · 0 评论 -
数学专项number_theory:UVa 10539
简而言之,almostprime就是prime的n次方数(n>2)。先筛出10^6内的prime,然后遍历所有素数,枚举素数的次方数即可。因为a^n增长的非常快,所以时间复杂度是可以接受的。#include #include #include using namespace std;int T,p;int vis[1000010];int prime[1000010];void原创 2013-04-30 20:48:13 · 899 阅读 · 0 评论 -
数学专项number_theory:UVa 11105
先用类似筛素数的方法,筛出primeH_number。然后所有primeH_number两两相乘所得的数即为semi-primeH_number了。#include #include #include using namespace std;#define M 1000010int vis[M];int prime[M],p;int cnt[M];void init(){原创 2013-04-30 20:49:27 · 786 阅读 · 0 评论 -
数学专项number_theory:UVa 10692
只能说数论方面的基本知识还是太匮乏了,而且lrj书上处理的情况都比较特殊。导致一遇到a和m不互质的情况我就一筹莫展了……无意间找到了一个公式才让我解决了这道题:a^x≡a^(x%phi(c)+phi(c))(mod c)。这个公式对a、c不互质的情况也成立,应该算是欧拉公式的扩展吧,可是因为没有系统学习过,所以也不知道怎么证明。求数学帝指点,或者推荐点资料神马的。#include #incl原创 2013-05-21 12:58:15 · 721 阅读 · 0 评论 -
数学专项number_theory:UVa 10951
题目大意就是在n的剩余系下求两个多项式的gcd多项式。很自然的可以想到用欧几里得算法,而且n保证为质数,所以求逆也很方便。至于保存多项式,我用一个vector来从高位到低位来保存一个多项式。#include #include #include #include using namespace std;int pow_mod(int a,int n,int m){ if(n=原创 2013-05-23 15:01:04 · 1024 阅读 · 0 评论 -
数学专项number_theory:UVa 11490
问题就是求满足方程6*d*d+7*a*d=s的所有正整数解。因为s#include #include #include using namespace std;typedef long long LL;const LL mod=100000007;LL s;int main(){ freopen("in.txt","r",stdin); while(cin>>s原创 2013-05-10 21:18:28 · 744 阅读 · 0 评论 -
数学专项number_theory:UVa 11728
直接O(n^2)暴力预处理出1-1000内数的因子和即可。对于大于1000的数完全不需要去考虑,原因是显然的,一个数的因子之和必然大于自身(质数为自身加一,1为自身)。#include #include #include using namespace std;int ans[1010];void init(){ memset(ans,-1,sizeof(ans));原创 2013-05-10 21:20:03 · 926 阅读 · 0 评论 -
数学专项number_theory:UVa 10236
需要推之一个结论,即gcd(f[n],f[m])=f[gcd(n,m)],有了这个结论就可以做这题了。在递推fibonacci数列的时候需要一些小技巧。#include #include #include #include #include using namespace std;const int maxn=22010;const long double inf=1e9;原创 2013-11-08 23:06:56 · 651 阅读 · 0 评论