摘要: 题目的思路还是很简单的,找出这些组合数中最大的公约数;其中C(n,k)=n ! /k!/(n-k)!所以枚举每个素因数,用(n!)的减去(k!)和(n-k)!的就行了...最后取每组的最小值 1 #include 2 #include 3 #include 4 5 using namespace std; 6 const int maxn=100010; 7 const int inf=0x3fffffff; 8 int prime[maxn],num; 9 bool isprime[maxn];10 int cnt[maxn],lim;11 typedef unsigned long... 阅读全文
posted @ 2013-08-26 13:11 Yours1103 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 这道题可以说是模拟,也可以说是数学题;以前在codeforce做过一题类似的,但是写的好长好长,后来看了大神写的代码后被折服... 1 #include 2 int main(){ 3 int n,a,b,c,d,e,f,x,y; 4 int u[4]={0,5,3,1}; 5 while(1){ 6 scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f); 7 if(a==0&&b==0&&c==0&&d==0&&e==0&&am 阅读全文
posted @ 2013-08-25 22:07 Yours1103 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 简单模拟: 1 #include 2 #include 3 using namespace std; 4 int n,m,cnt; 5 int a[1010],b[1010]; 6 7 inline bool judge() 8 { 9 for(int i=0;i<n;i++)10 if(a[0]!=a[i]) return false;11 return true;12 }13 14 int main()15 {16 while(scanf("%d",&n)==1)17 {18 if(n==0) return 0;19 ... 阅读全文
posted @ 2013-08-25 22:03 Yours1103 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 暑假集训做的第一个题,模拟,挺简单的,不过要细心点...没什么好说的,直接贴代码; 1 #include 2 #include 3 using namespace std; 4 5 bool rec[33][33]; 6 int n,x,y; 7 char c; 8 9 int main()10 {11 while(scanf("%d",&n)!=EOF)12 {13 int m=1;14 while(n--)15 {16 scanf("%d%d",&x,&y);17 memse... 阅读全文
posted @ 2013-08-25 21:59 Yours1103 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 又是个水题,刚刚开始没有用搜索,因为对于反素数有:n=2^t1*3^t2^5^t3*7^t4..... 这里有 t1>=t2>=t3>=t4。而且相同的因数的情况下,素数越不同越好。哪知道这个方法错了! = =。看来还得中规中矩得用dfs。我觉得还可以优化下,感觉搜索干了很多无用的活儿。搜索还得好好练练啊... 1 #include 2 #define LL long long 3 using namespace std; 4 int prim[16] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; 阅读全文
posted @ 2013-08-25 21:31 Yours1103 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 每个数都可以分解成素数的乘积:写成指数形式:n=p1^e1*p2^e2*...*pn^en;(p都是素数)那么n的因数的数量m=(e1+1)*(e2+1)*...*(en+1);所以用筛选法筛出1-n的各个素因数的数量;然后容易得到n!的各个素因数的数量;因为C(n,k)=n!/k!/(n-k)!;所以接下来的事就容易办了.....我的代码: 1 #include 2 using namespace std; 3 int e[432][432],sum[432][432],n,num,kk; 4 bool prim[432]; 5 long long ans; 6 int main() 7 { 阅读全文
posted @ 2013-08-25 19:34 Yours1103 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 这道题目看上去不难,但我一直想不懂为什么k会比m大```我的第一感觉想试试gcd,不敢下手,题目意思还不完全懂;看了看网上的题解,发现大部分都是用容斥原理做,这东西我还没学, = =!后来明白题目意思了,也就清楚了```题解:欧几里德算法: gcd(b×t+a,b)=gcd(a,b) (t为任意整数)则如果a与b互素,则b×t+a与b也一定互素,如果a与b不互素,则b×t+a与b也一定不互素故与m互素的数对m取模具有周期性,则根据这个方法我们就可以很快的求出第k个与m互素的数 1 #include 2 using namespace std; 3 int s[10 阅读全文
posted @ 2013-08-24 23:38 Yours1103 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 上一题是欧拉函数打表,这一题赤裸裸的欧拉函数;就当熟悉下模板把;其实自己以前也没敲过``` 1 #include 2 using namespace std; 3 long long MakePhi(long long n) 4 { 5 long long res = n, i; 6 for(i = 2; i <= n; ++ i) 7 { 8 if(n % i == 0) 9 {10 res -= res / i;11 while(n % i == 0)12 ... 阅读全文
posted @ 2013-08-24 23:01 Yours1103 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 从来没有接触过完全剩余系,不会证明,知道看了别人的题解才知道要用欧拉函数;下面是证明过程:p是奇素数,如果{xi%p | 1 2 using namespace std; 3 const int maxn=65540; 4 int phi[maxn]={0}; 5 void phi_table() 6 { 7 int i,j; 8 phi[1]=i; 9 for(i=2;i<maxn;i++)10 {11 if(!phi[i])12 for(j=i;j<maxn;j+=i)13 {14 ... 阅读全文
posted @ 2013-08-24 22:22 Yours1103 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 这道题WA了我好多次,就像比赛的时候一样,都是些小错误,但oj是无情的,让我一W再W;当时正和安叔聊着天,安叔一直在批评我们平时做题很水,太依赖死东西了。以后真的不能再依赖模板了```说说这题吧。思路很容易想到```我刚刚开始直接用gcd的办法,超时了,没办法,数据很大```先算出/g=a/b;然后对g用那个Pollard_rho算法得出所有的素因数,排序,把相同的元素结合在一起;这样可以保证待会儿分解的时候不会有相同的因数;分解的时候,从g的平方根开始用dfs,很简单```贴下代码: 1 #include 2 #include 3 #include 4 #include 5 #in... 阅读全文
posted @ 2013-08-24 17:04 Yours1103 阅读(251) 评论(0) 推荐(0) 编辑