Summation of Four Primes Input: standard input Output: standard output Time Limit: 4 seconds Euler proved in one of his classic theorems that prime numbers are infinite in number. But can every number be expressed as a summation of four positive prim…
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10168.html 原创:Summation of Four Primes - PC110705 作者:MilkCu 题目描述 Summation of Four Primes   Waring's prime number conjecture states that every odd integer is either pri…
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 XOR的性质 GCD 由于题目只给出一个n,我们要求对数,能做的也始终暴力枚举a,b,这样就有n^2的复杂度,由于n很大,根本过不了. 于是我们就想用到其中一些性质,如XOR 与GCD,不妨假设 a xor b = c,并且根据题意还知道, gcd(a,b) = c,也就说明c一定是a的因子,所以在枚举的…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=42  Fermat vs. Pythagoras  Background Computer generated and assisted proofs and verification occupy a small niche in the realm…
UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: #include <stdio.h> #include <string.h> long long a, p; long long pow_mod(long long x, long long k, long long mod) { long long ans = 1; while (k…
UVA 12103 - Leonardo's Notebook 题目链接 题意:给定一个字母置换B.求是否存在A使得A^2=B 思路:随意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) 分, 而且每一份的长度都为 L / gcd(l,k).因此平方对于奇数长度不变,偶数则会分裂成两份长度同样的循环,因此假设B中偶数长度的循环个数不为偶数必定不存在A了 代码: #include <stdio.h> #include <string.h> const int N = 30…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4109 题意: 输入正整数n和k(1≤n,k≤1e9),计算sum(k mod i)(1≤i≤n). 分析: 被除数固定,除数逐次加1,直观上余数也应该有规律.假设k/i的整数部分等于d,则k mod i = k-i*d.因为k/(i+1)和k/i差别不大,如果k/(i+1)的整数部…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4515 题意: 给出整数a.b,统计a和b(包含a和b)之间的整数中,数字0,1,2,3,4,5,6,7,8,9分别出现了多少次.1≤a,b≤1e8. 分析: 解决这类题目的第一步一般都是:令f(n,d)表示0-n中数字d出现的次数,则所求的就是f(b,d)-f(a-1,d).例如,…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2629 题意: 输入两个非负整数a.b和正整数n(0≤a,b<2^64,1≤n≤1000),你的任务是计算f(a^b)除以n的余数.其中f(0)=0,f(1)=1,且对于所有非负整数i,f(i+2)=f(i+1)+f(i). 分析: 所有计算都是对n取模的,设F(i)=f(i)…
UVA 11246 - K-Multiple Free set 题目链接 题意:一个{1..n}的集合.求一个子集合.使得元素个数最多,而且不存在有两个元素x1 * k = x2,求出最多的元素个数是多少 思路:推理一下, 一開始n个 先要删除k倍的,删除为{k, 2k, 3k, 4k, 5k, 6k...},会删掉多余的k^2,因此在加回k^2倍的数 然后如今集合中会出现情况的仅仅有k^2的倍数,因此对k^2倍的数字看成一个新集合重复做这个操作就可以.因此最后答案为n - n / k + n…