
数论
文章平均质量分 68
qichi_bj
这个作者很懒,什么都没留下…
展开
-
质因数分解算法
看《单墫老师教你学数学》了解了一个很巧妙的质因数分解的算法,C++代码如下:/* * 求正整数n的最小质因数 */uint64_t FactorDecomposer::minimalPrimeFactor(uint64_t n) { if ( n % 2 == 0 ) return 2; uint64_t M = n, N = n, b = 3, r = 0; while原创 2012-10-20 15:03:42 · 1123 阅读 · 0 评论 -
UVa11361 Investigating Div-Sum Property
给定整数 A ,B ,K 求 区间[A, B] 中被 K 整除且各位数之和被 K 整除的数有多少个,1 <= A <= B < 2^31 且 0< K < 10000package UVa11361;import java.util.Scanner;public class Main { private static final int MAX_BIT = 16; pr原创 2012-12-29 11:53:04 · 569 阅读 · 0 评论 -
数论问题的几个工具函数
包括求最大公约数、指数运算求模、高斯 φ 函数 、模运算乘法逆的几个工具函数:public class NumberTheoryUtil { // 用于返回结果 使 ax + by = d public static class Result { int a; int b; int d; public Result(int a, int b, int d) { this.原创 2012-12-21 23:03:47 · 644 阅读 · 0 评论 -
UVa 10139 Factovisors
这道题同样的代码用 JAVA 会超时,用 C++ 才通过。#include #include #include using namespace std;// 素数筛的数组长度long LEN = 1 << 16;// 用于保存筛出的素数vector primes;// 利用筛法求 2^16 以内的素数,保存到 primes 全局变量void init() { bo原创 2013-01-13 08:16:26 · 514 阅读 · 0 评论