上一页 1 ··· 3 4 5 6 7 8 9 下一页

2013年2月21日

类似于素数筛选法做,预处理一下就不会超时(POJ 3292)

摘要: import java.io.*;import java.util.*;import java.math.*;public classMain { static final int MAXN = 1000005; int sup, p[], n, count[]; boolean flag[]; void getH() { p = new int[MAXN]; flag = new boolean[MAXN]; for (int i = 5; i < MAXN; i += 4) { if (flag[i] == false) { p[sup++] = i; for (... 阅读全文

posted @ 2013-02-21 19:42 Sure_Yi 阅读(214) 评论(0) 推荐(0) 编辑

2013年2月20日

LCM问题(素数,约数处理, UVA 10791)

摘要: 注意:1. 2147483647,也就是(1 << 31) - 1,是素数,所以结果要用long2. 1 要特殊处理一下3. LCM 的一些性质 import java.io.*;import java.util.*;import java.math.*;public classMain { static final int MAXN = 100005; int p[], sup, n; boolean flag[]; void getPrimes() { p = new int[MAXN]; flag = new boolean[MAXN]; for (int i = 2; i 阅读全文

posted @ 2013-02-20 21:59 Sure_Yi 阅读(226) 评论(0) 推荐(0) 编辑

大数模运算(POJ 1845)

摘要: http://blog.sina.com.cn/s/blog_6635898a0100omcn.html直接抄过来了(不好意思)题意:求A^B的所有约数之和 Mod 9901。思路:大数模运算。两个最基本公式:(A*B)%C = ((A%C)*(B%C))%C 和 (A+B)%C = ((A%C)+(B%C))%C 。用__int64的原因为 n = cnt[i] * B (cnt[i]为A第i个素因子的个数)可能会超int。1: 对A进行素因子分解得A = p1^a1 * p2^a2 * p3^a3 *...*pn^an.故A^B = p1^(a1*B) * p2^(a2*B) *...* 阅读全文

posted @ 2013-02-20 20:28 Sure_Yi 阅读(507) 评论(0) 推荐(0) 编辑

-和~混合使用

摘要: ~n == n * (-1) - 1;-~n == n + 1;~-n == n - 1; 阅读全文

posted @ 2013-02-20 18:55 Sure_Yi 阅读(166) 评论(0) 推荐(0) 编辑

2的模幂计算(UVA 11609)

摘要: import java.io.*;import java.util.*;import java.math.*;public classMain { static final int MOD = 1000000007; //n * (C(n - 1, 0) + C(n - 1, 1) + ... + C(n - 1, n - 1)) == n * 2 ^ (n - 1) {模幂} long BigMod(int n) { long res = 1, temp = 2; while (n > 0) { if ((n & 1) != 0) res = (res * temp... 阅读全文

posted @ 2013-02-20 10:15 Sure_Yi 阅读(246) 评论(0) 推荐(0) 编辑

求所有约数,暴力求解(UVA 10892)

摘要: import java.io.*;import java.util.*;import java.math.*;public classMain { int n, len; LinkedList<Integer>list; int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); } int LCM(int a, int b) { return a / GCD(a, b) * b; } boolean isEqual() { return Math.sqrt(n) == (int)Math.sqrt(n); } vo... 阅读全文

posted @ 2013-02-20 08:49 Sure_Yi 阅读(220) 评论(0) 推荐(0) 编辑

2013年2月19日

UVA 11076

摘要: import java.io.*;import java.util.*;import java.math.*;public classMain { static final int MAXN = 13; int A[] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600}; // 阶乘 int a[] = new int[10], n, x; // 大整数应用注意,Java中没有unsigned,用BigInteger代替c++中的unsigned long long int sol... 阅读全文

posted @ 2013-02-19 21:22 Sure_Yi 阅读(191) 评论(0) 推荐(0) 编辑

Java 大整数 BigInteger, BigDecimal使用方法

摘要: 从左往右计算BigInteger t = BigInteger.ONE; t = t.multiply(BigInteger.valueOf(3)).add(BigInteger.valueOf(2));answer : 5 t = BigInteger.ONE; t = t.add(BigInteger.valueOf(2)).multiply(BigInteger.valueOf(3));anwser : 6http://www.java3z.com/cwbwebhome/article/article8/81439.html?id=4322例子: BigInteger a = ... 阅读全文

posted @ 2013-02-19 20:55 Sure_Yi 阅读(983) 评论(0) 推荐(0) 编辑

容斥原理(模版 ZOJ 2836)

摘要: import java.io.*;import java.util.*;import java.math.*;public class Main { long m, ans; int n, a[]; long GCD(long a, long b) { // 中间结果用long保险,下LCM同 return b == 0 ? a : GCD(b, a % b); } long LCM(long a, long b) { return a / GCD(a, b) * b; } void dfs(long t... 阅读全文

posted @ 2013-02-19 20:04 Sure_Yi 阅读(196) 评论(0) 推荐(0) 编辑

2013年2月18日

排列组合递推公式以及代码

摘要: A(n, m) = A(n - 1, m - 1) + A(n - m, m) {n在下,m在上,下同}UESTC 1721static final int MOD = 1000000007; static final int MAXN = 2005; int A[][]; void solve() { A = new int[MAXN][MAXN]; for (int i = 1; i < MAXN; i++) { A[i][1] = A[i][i] = 1; } for (int i = 3; i < MAXN; i++) { for (int j = 2; j < i; 阅读全文

posted @ 2013-02-18 21:37 Sure_Yi 阅读(961) 评论(0) 推荐(0) 编辑

上一页 1 ··· 3 4 5 6 7 8 9 下一页

导航