Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
排列组合的要给tong long, 给int会因为溢出导致WA#include <iostream> #include <stdio.h> #define MAX 1048580 #define PLEN 85000 using namespace std; bool isprime[MAX]; int prime[PLEN]; int i, j, X; int main() { //prime fill(isprime, isprime + MAX, true); isprime[0] = false; isprime[1] = false; int sum = 0; for (i = 2; i < MAX; i++) { if(isprime[i]) { prime[sum++] = i; for (j = i + i; j < MAX; j += i) isprime[j] = false; } } while (scanf("%d", &X) == 1) { if (isprime[X]) { printf("1 1\n"); continue; } int index = 0, ans = 0; long long A = 1; //decomposite prime factors { while (X > 1) { int mod = prime[index++]; int cnt = 1; while (X % mod == 0) { ans++; X /= mod; A *= cnt++; } } } //pow, permutation and combination long long pow = 1; for (j = 2; j <= ans; j++){ pow *= j; } pow /= A; printf("%d %lld\n", ans, pow); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator