Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

强人们看看我怎么老是WA? 内有代码.

Posted by wronger at 2006-03-26 23:08:10 on Problem 2773
#include <stdio.h>
#include <math.h>

int a[30];

void seta(int a[], int m){
    int i, j;
	a[0]=0; j=1;
	for( i=2; m>1 ; ){
		if(m%i!=0) i++;
		else if(m%i==0){
			m=m/i;
			if(i!=a[j-1]){
				a[j++]=i;
				a[0]++;
			}
		}
	}
}

int main(){
	int m, k, r, res, i, j;
	while(scanf("%d%d", &m, &k)==2){
		if(m==1){
			printf("%d\n", k);
			continue;
		}
		seta(a, m);
		r=m;
		for(i=1; i<=a[0]; i++){
			r=r*(a[i]-1)/a[i];
		}
		res=k/r*m;
		k=k%r; 
        if(k==0) res--;
		for(i=1; k>0; i++){
			for(j=1; a[j]<=i && j<=a[0]; j++){
				if(i%a[j]==0) goto L;
			}
			k--;
L:;
		}
		i--;
		res+=i;
		printf("%d\n", res);
	}
	return 0; 
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator