Description
N children are sitting in a circle to play a game.
The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The game starts from theK-th child, who tells all the others the integer on his card and jumps out of the circle. The integer on his card tells the next child to jump out. LetA denote the integer. If A is positive, the next child will be theA-th child to the left. If A is negative, the next child will be the (−A)-th child to the right.
The game lasts until all children have jumped out of the circle. During the game, thep-th child jumping out will get F(p) candies where F(p) is the number of positive integers that perfectly divide p. Who gets the most candies?
Input
Output
Output one line for each test case containing the name of the luckiest child and the number of candies he/she gets. If ties occur, always choose the child who jumps out of the circle first.
Sample Input
4 2 Tom 2 Jack 4 Mary -1 Sam 1
Sample Output
Sam 3
Source
心情不好,若干脑残错误==
题意:N个小孩坐一圈,每个小孩有一个数字,开始时第k个出列,出列的这个小孩的数字是整数,往右数这个数个下一个出列;负数,往左数个小孩出列。以此类推,第p个出列的小孩得到的糖果数是p的约数个数,问最多得糖果的是谁,得了几个。
首先反素数打个表,我就直接贴的网上的数据了。然后,坐成圈就让我想到把环扩二倍orz根本用不着啊,取模就够了啊。绝对位置等于当前位置+/-相对位置,其实没多难的题就是想不到啊啊啊啊啊
/***************
poj2886
2016.3.8
21804K 1157MS C++ 1822B
***************/
#include
#include
#include
using namespace std;
#define maxn 500005
int a[37]={1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,
55440,83160,110880,166320,221760,277200,332640,498960,500001};
int b[37]={1,2,3,4,6,8,9,10,12,16,18,20,24,30,32,36,40,48,60,64,72,80,84,90,96,100,108,120,128,144,160,168,180,192,200,1314521};
char name[maxn][15];
int pos[maxn];
struct node
{
int l,r,tot;
}num[maxn*4];
void build(int rt,int l,int r)
{
int mid=(l+r)/2;
num[rt].l=l;num[rt].r=r;
if(l==r)
{
num[rt].tot=1;
return;
}
// printf("rt=%d tot=%d\n",rt,num[rt].tot);
build(rt<<1,l,mid);
build(rt<<1|1,mid+1,r);
num[rt].tot=num[rt<<1].tot+num[rt<<1|1].tot;
}
int update(int rt,int k)
{
num[rt].tot--;
if(num[rt].l==num[rt].r)
return num[rt].l;
if(k<=num[rt<<1].tot) update(rt<<1,k);
else update(rt<<1|1,k-num[rt<<1].tot);
}
int main()
{
//freopen("cin.txt","r",stdin);
int n,k;
while(~scanf("%d%d",&n,&k))
{
for(int i=1;i<=n;i++)scanf("%s%d",name[i],&pos[i]);
// for(int i=1;i<=n;i++)printf("%s% d\n",name[i],pos[i]);
build(1,1,n);
int cnt=0;
while(a[cnt]<=n) cnt++;
cnt--;
int ps=0;
pos[ps]=0;
// printf("tot=%d\n",num[1].tot);
for(int i=0;i0)
k = ((k + pos[ps] - 2) % num[1].tot + num[1].tot) % num[1].tot + 1;
else k = ((k + pos[ps] - 1) % num[1].tot + num[1].tot) % num[1].tot + 1;
// cout<