题意:给定 n,k,求 while(i <=n) k % i的和. 析:很明显是一个数论题,写几个样例你会发现规律,假设 p = k / i.那么k mod i = k - p*i,如果 k / (i+1) 也是p,那么就能得到 : k mod (i+1) = k - p*(i+1) = k mod i - p.所以我们就能得到一个等差数列 k mod (i+1) - k mod i = -p,首项是 p % i. 代码如下: #pragma comment(linker, "/STAC…
链接: 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)的整数部…
11490 - Just Another Problem option=com_onlinejudge&Itemid=8&page=show_problem&category=474&problem=2485&mosmsg=Submission+received+with+ID+13809788" target="_blank" style="">题目链接 题意:有S个士兵.排成一个矩阵,矩阵中能够有两个洞,要…
题意: 给出n, k,求 分析: 假设,则k mod (i+1) = k - (i+1)*p = k - i*p - p = k mod i - p 则对于某个区间,i∈[l, r],k/i的整数部分p相同,则其余数成等差数列,公差为-p 然后我想到了做莫比乌斯反演时候有个分块加速,在区间[i, n / (n / i)],n/i的整数部分相同,于是有了这份代码. #include <cstdio> #include <algorithm> using namespace std;…
UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that instruct a robot arm in how to manipulate blocks that lie on a flat table. Initially there are nblocks on the table (numbered from 0 to n-1) with block bi…
UVA - 524 Prime Ring Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers into each circle separately, and the sum of number…
Joseph The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, ..., n, standing in circle every mth is going to be executed and only the life of the last remaining per…