Aladdin and the Flying Carpet LightOJ - 1341(算数基本定理)
2018-11-15 21:48
232 查看
题目链接:qaq
题意:找出符合的因子对数的个数
思路:知道算数基本定理后就简单了(感觉和暴力的复杂度一样啊QAQ。。难受)
附上代码:
[code]#include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; const int MAXN = 1000100; int prime[MAXN + 1]; long long sum=1; void getPrime() { memset(prime, 0, sizeof(prime)); for (int i = 2; i <= MAXN; i++) { if (!prime[i])prime[++prime[0]] = i; for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++) { prime[prime[j] * i] = 1; if (i%prime[j] == 0) break; } } } long long factor[100][2]; int fatCnt; void getFactors(long long x) { fatCnt = 0; long long tot=0; long long tmp = x; for (int i = 1; prime[i] <= tmp / prime[i]; i++) { factor[fatCnt][1] = 0; tot=0; if (tmp%prime[i] == 0) { factor[fatCnt][0] = prime[i]; while (tmp%prime[i] == 0) { factor[fatCnt][1]++; tmp /= prime[i]; tot++; } sum*=(tot+1); fatCnt++; } } if (tmp != 1) { factor[fatCnt][0] = tmp; factor[fatCnt++][1] = 1; sum*=2; } } int main (void){ int t; scanf("%d",&t); int ca=1; getPrime(); while(t--){ sum=1; long long n,m; scanf("%lld%lld",&n,&m); printf("Case %d: ",ca++); if(m>sqrt(n)){ printf("0\n"); continue; } getFactors(n); //printf("%d\n",sum); sum=sum/2; for(int i=1;i<m;i++){ if(n%i==0) sum--; } printf("%lld\n",sum); } return 0; }
阅读更多
相关文章推荐
- LightOj1341_Aladdin and the Flying Carpet_算数基本定理
- 【算数基本定理(唯一分解定理)】Aladdin and the Flying Carpet LightOJ - 1341
- lightoj 1341 - Aladdin and the Flying Carpet / lightoj 1236 - Pairs Forming LCM(算术基本定理)
- LightOJ 1341 Aladdin and the Flying Carpet(算术基本定理)
- LightOJ 1341 - Aladdin and the Flying Carpet(算术基本定理啊)
- Light OJ 1341 Aladdin and the Flying Carpet(算数基本定理)
- LightOJ 1341 Aladdin and the Flying Carpet(算术基本定理)
- 【基本算术定理 && 质因数分解】LightOJ - 1341 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet LightOJ - 1341 数论/唯一分解定理
- LightOJ - 1341 Aladdin and the Flying Carpet(唯一分解定理)
- Lightoj1341——Aladdin and the Flying Carpet(算术基本定理)
- Aladdin and the Flying Carpet LightOJ - 1341(合数)唯一分解定理
- LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
- LightOJ 1341 Aladdin and the Flying Carpet
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
- LightOJ 1341 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet LightOJ - 1341
- LightOJ 1341 Aladdin and the Flying Carpet
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】