UVa 1363 Joseph's Problem (数论)】的更多相关文章

题意:给定 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…
/** 题目:Joseph's Problem 链接:https://vjudge.net/problem/UVA-1363 题意:给定n,k;求k%[1,n]的和. 思路: 没想出来,看了lrj的想法才明白. 我一开始往素数筛那种类似做法想. 想k%[1,n]的结果会有很多重复的,来想办法优化. 但没走通. 果然要往深处想. 通过观察数据发现有等差数列.直接观察很难确定具体规律:此处应该想到用式子往这个方向推导试一试. lrj想法: 设:p = k/i; 则:k%i = k-i*p; 容易想到…
链接: 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://vjudge.net/problem/UVA-1363 n 题意:求 Σ  k%i i=1 除法分块 如果 k/i==k/(i+1)=p 那么 k%(i+1)=k-(i+1)*p= k-i*p-p = k%i-p 所以 商相同时,余数为等差数列 我不知道为什么交到vjudge一直WA,网上搜的题解交上去也WA #include<cmath> #include<cstdio> using namespace std; int main() { int n,k,i,j,…
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 1380 A Scheduling Problem 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=41557 思路:   给出一个任务调度树,单向边u->v表示u必须在v之前完成,双向边u-v表示无所谓方向. 题目给出定理,首先dfs求得忽略无向边后的最长链点数k,那么问题就是判断是否可以通过无向边定向从而使得最长链点数不超过k.用dp的判断. 设f[i]表示以i为根的子树中所有的边定向后最长链点数不超过…
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…