Shirlies
宁静专注认真的程序媛~
posts - 222,comments - 49,views - 71万

随笔分类 -  acm_数论

hdu 3802【Ipad,IPhone】
摘要:这两个解题报告比较详细:http://wutyyzchangde.blog.163.com/blog/static/172226566201132311311374/我主要是参考这个解题报告的http://www.cnblogs.com/zjh10/articles/2035938.html这个可以看看。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 typedef __int64 ll; 5 struct node 6 { 7 ll matrix[2][2]; 8 }; 9 10 ll pow_mod(ll a 阅读全文
posted @ 2012-06-07 09:47 Shirlies 阅读(390) 评论(0) 推荐(0) 编辑
hdu 1757【A Simple Math Problem】
摘要:矩阵相乘代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 struct matrix 5 { 6 int g[10][10]; 7 }mt; 8 9 int kk,m;10 11 matrix multi(matrix a,matrix b)12 {13 matrix ans;14 15 for(int i = 0;i < 10;i ++)16 {17 for(int j = 0;j < 10;j ++)18 {19 int t = 0;20 ... 阅读全文
posted @ 2012-05-25 21:24 Shirlies 阅读(194) 评论(0) 推荐(0) 编辑
hdu 2824【The Euler function】
摘要:代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 5 const int maxn = 3000000+100; 6 int phi[maxn]; 7 int a,b; 8 9 void phi_table(int n)10 {11 memset(phi,0,sizeof(phi));12 phi[1] = 1;13 for(int i = 2;i <= n;i ++)14 {15 if(!phi[i])16 {17 ... 阅读全文
posted @ 2012-05-23 18:00 Shirlies 阅读(166) 评论(0) 推荐(0) 编辑
uva 10717【Mint】
摘要:这一题做的有点小苦,但是最终取得了成功,(*^__^*) 嘻嘻……起初不知道哪里出问题了,一直WA,然后对照网上的代码一步一步的改啊,提交啊,最终AC了,然后又一步一步的改回到自己原来的样子,(~ o ~)~zZ错误找到了。。。不知道WA了多少次,又AC了多少次,不计算了,而且我的代码运行时间比网上的代码时间更短,成就啊,不过有点小浪费空间,其实两个循环可以合并,就少一点空间了。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int length[60]; 阅读全文
posted @ 2012-04-15 13:06 Shirlies 阅读(326) 评论(0) 推荐(0) 编辑
uva 10791【 Minimum Sum LCM】
摘要:每做一题就对数学更加崇拜!看了别人做的才会做的,细节问题不会处理http://www.mysjtu.com/page/M0/S653/653211.html还是贴上自己的代码吧。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 5 int n; 6 7 long long solve() 8 { 9 int m = (int)sqrt(n + 0.5);10 long long sum = 0;11 int count = 0;12 for(int i = 2;i &l 阅读全文
posted @ 2012-04-14 17:40 Shirlies 阅读(192) 评论(0) 推荐(0) 编辑
uva 11121【base -2】
摘要:uva上面的题目就是不一样啊。。。表扬一下“经典”。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 int a[100]; 5 int n; 6 void solve() 7 { 8 memset(a,0,sizeof(a)); 9 int len = 0;10 while(n!=0)11 {12 a[len] = (n%2 + 2)%2;//这个取模的方法很有用13 n = (n - a[len ++])/(-2);14 }15 if(len == 0)... 阅读全文
posted @ 2012-04-14 15:20 Shirlies 阅读(185) 评论(0) 推荐(0) 编辑
uva 106【Fermat vs. Pythagoras】
摘要:神奇的一题,偶对数学的崇拜加深了!题解:http://www.algorithmist.com/index.php/UVa_106我自己再简单的解释一下吧。。。x2+y2=z2(这些都是在x,y,z互质的情况下推的),可以变成:y2=(z - x) * (z + x),我们再变换一下:(y/2)2 = (z - x)/2 * (z +x )/2 ((z-x)/2和(z + x)/2必然为平方数,因为(z - x)/2和(z + x)/2必然是互质,没有共同的因子,自己可以好好想想,推一推) ,设r2 = (z - x)/2,s2 = (z +x )/2,前面是在互质的情况下退出来的,但是反推的 阅读全文
posted @ 2012-04-14 12:01 Shirlies 阅读(462) 评论(0) 推荐(0) 编辑
uva 10006
摘要:一题如此基础的题目,搞了那么久,晕。。。不过有很多细节错误自己改过来了,给自己鼓鼓掌^_^求幂的时候要用longlong型的,可是为什么啊?x的值根本就不可能比65000大啊,每次都取模啊,求反例。。。。。。还有判断素数要在前,刘汝佳先生说过&&是短路来着。。。。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 5 int prime[65002]; 6 int n; 7 8 void is_prime() 9 {10 int m = sqrt( 阅读全文
posted @ 2012-04-13 20:27 Shirlies 阅读(639) 评论(1) 推荐(0) 编辑
hdu 1222
摘要:简单题~~~#include <iostream>using namespace std;int gcd(int a,int b){if(b==0)return a;elsereturn gcd(b,a%b);}int main(){int T;int m,n;cin>>T;while(T--){cin>>m>>n;if(m==1){cout<<"NO"<<endl;continue;}if(gcd(n,m)==1){cout<<"NO"<<endl;}els 阅读全文
posted @ 2012-02-13 18:52 Shirlies 阅读(140) 评论(0) 推荐(0) 编辑
hdu acm1286
摘要:欧拉函数φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数就是1本身)。 (注意:每种质因数只一个。比如12=2*2*3欧拉公式那么φ(12)=12*(1-1/2)*(1-1/3)=4)#include "stdio.h"int prime[10000]={1,2,3};int main(){int t;int n;int count;int i,k=3,j,ok;for(i=4;i<32768;i++){ok=1;for(j=1 阅读全文
posted @ 2012-01-18 17:26 Shirlies 阅读(167) 评论(0) 推荐(0) 编辑
hdu acm 2504
摘要:a/gcd(a,b)与b/gcd(a,b)互素就可以做出来了……#include "stdio.h"int gcd(int a,int b){if(a%b==0)return b;elsereturn gcd(b,a%b);}int main(){int a,b;int t,temp;int i;scanf("%d",&t);while(t--){scanf("%d%d",&a,&b);temp=a/b;for(i=2;i<1000000;i++){if(gcd(i,temp)==1){break;}}p 阅读全文
posted @ 2012-01-18 16:22 Shirlies 阅读(232) 评论(0) 推荐(0) 编辑
hdu acm1713
摘要:思路是:通分后求分子的最小公倍数,在除以通分后的分母(看了别人的思路才知道分数的最小公倍数是这样求的,起初只是知道要求公倍数,但是不知道怎么求,汗,我可怜的数学啊~~~)#include "stdio.h"__int64 gcd(__int64 a,__int64 b){if(a%b==0)return b;elsereturn gcd(b,a%b);}int main(){int T;__int64 t1,q1,t2,q2,ts,kq,t;scanf("%d",&T);while(T--){scanf("%I64d/%I64d %I6 阅读全文
posted @ 2012-01-18 10:07 Shirlies 阅读(371) 评论(0) 推荐(0) 编辑
hdu acm2138
摘要:#include "stdio.h"#include "math.h"int is_prim(int n){int i;for(i=2;i<=sqrt(n);i++)//晕,这里用i*i<=n就超时了,没有头绪,莫名其妙,网上看了别人的代码,就将它改成这样,竟然A了,汗~~~……………………哈,忽然想到是为什么了,理由是:当循环到i=46340时i*i<n;但i=46341时i*i=2147488281,超过了int的最大值,溢出变成负数,仍然满足i*i<n!n不是太大的话,运气好还能碰上101128442溢出后等于2147483 阅读全文
posted @ 2012-01-17 23:12 Shirlies 阅读(325) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示