Time Limit: 5000MS | Memory Limit: 131072K | |
Total Submissions: 8055 | Accepted: 2406 | |
Case Time Limit: 2000MS |
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 the K-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. Let A denote the integer. If A is positive, the next child will be the A-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, the p-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
首先要懂什么是反素数(不解释) 后面给出用暴力求反素数代码:
#include<iostream> #include<cstring> #include<string> #include<cstdio> using namespace std; const int maxn = 500010; int num[maxn]; char name[maxn][11]; struct Node { int left,right,sum; int mid() { return left + (right - left) /2 ; } }tree[maxn*5]; int RPrime[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 Prime_num[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,1016000 }; void build(int left,int right,int n) { tree[n].left = left; tree[n].right = right; tree[n].sum = right - left + 1; if(left == right) return ; else { int mid = tree[n].mid(); build(left,mid,n*2); build(mid+1,right,n*2+1); } } int query(int num,int n) { tree[n].sum--; if(tree[n].left == tree[n].right) return tree[n].left; else { if(num<=tree[n*2].sum) return query(num,2*n); else return query(num-tree[n*2].sum,2*n+1); } } int main() { int n,k; while(scanf("%d %d",&n,&k)!=EOF) { int i=0,j; while(RPrime[i] <= n) { i++; } int p =0 ; p = i-1; build(1,n,1); int hight =0; hight = RPrime[p]; int num_max = Prime_num[p]; for(j=1;j<=n;++j) { scanf("%s %d",&name[j],&num[j]); } int index; k--; for(j=0;j<hight;++j) { n--; index = query(k+1,1); if(j==hight-1) break; if(num[index] > 0) k = (k + num[index] - 1)%n; else k = ((k + num[index])%n+n )%n ; } printf("%s %d ",name[index],num_max); } return 0; }
反素数:
#include<iostream> using namespace std; int judge(int n) { if(n==1) return 1; int i,k=2; for(i=2;i<n;i++) {if(n%i==0)k++;} return k; } int main() { int t,a,b,max,i,c,f; while(scanf("%d",&t)!=EOF) { while(t--) 数据组数 { scanf("%d%d",&a,&b); max=judge(a);f=a; for(i=a+1;i<=b;i++) { c=judge(i); if(c>max) { max=c;f=i; printf("%d:%d",c,f) ;//c为反素数因子个数 f为反素数 } } } } return 0; }