lightoj 1341__Aladdin and the Flying Carpet
2017-07-12 09:08
281 查看
题目描述:
It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.
输入输出直接看样例吧:
2
10 2
12 2
Case 2: 2
一道应用算术基本定理的数论题,至于算数基本定理百度百科,
我们利用这个定理可以计算出a的约数个数,由于约数成对,直接除以2就是约数对数,然后枚举区间[1,b]内a的约数,每有一个,则答案的约数对数-1,最后得出结果;
AC代码:
It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.
Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised himself as Aladdin's uncle, found a strange magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but
he knew that there was a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped, but not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.
Now you are given the area of the carpet and the length of the minimum possible side of the carpet, your task is to find how many types of carpets are possible. For example, the area of the carpet 12, and the minimum possible side of the carpet is 2, then there
can be two types of carpets and their sides are: {2, 6} and {3, 4}.
题意就是给你一个a,b然后求[b,a]区间内a的约数对数。
输入输出直接看样例吧:
input:
210 2
12 2
output:
Case 1: 1Case 2: 2
一道应用算术基本定理的数论题,至于算数基本定理百度百科,
我们利用这个定理可以计算出a的约数个数,由于约数成对,直接除以2就是约数对数,然后枚举区间[1,b]内a的约数,每有一个,则答案的约数对数-1,最后得出结果;
AC代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<stack> #include<queue> #include<algorithm> using namespace std; const int MAXM=1000010; bool prime[MAXM]; int rec[MAXM], cnt; void init_prime_table() { memset(prime,true,sizeof(prime)); prime[0]=prime[1]=false; for (int i = 2; i<=MAXM; ++i) { if (prime[i]) rec[cnt++] = i; for (int j =0;j<cnt&&rec[j]<=MAXM/i;++j) { prime[i*rec[j]]=false; if (i%rec[j]==0) break; } } } int cal(long long x) { int num=1; for(int i=0;i<cnt&&rec[i]<=sqrt(x);i++) { int cc=0; while(x%rec[i] == 0) { cc++; x/=rec[i]; } num*=(cc+1); } if(x>1) num*=2; return num; } int main() { int T; scanf("%d",&T); int cas=1; cnt=0; init_prime_table(); while(T--) { long long a,b; scanf("%lld%lld",&a,&b); if (a<b*b) { printf("Case %d: 0\n",cas); cas++; continue; } else { int num=cal(a); num=num/2; for (int i=1;i<b;i++) if (a%i==0) num--; printf("Case %d: %d\n",cas,num); cas++; } } return 0; }
相关文章推荐
- 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 约数的个数
- 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【整数分解】
- 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
- lightoj 1341 - Aladdin and the Flying Carpet / lightoj 1236 - Pairs Forming LCM(算术基本定理)
- LightOJ1341 Aladdin and the Flying Carpet
- LightOJ 1341 - Aladdin and the Flying Carpet(算术基本定理啊)
- LightOj1341_Aladdin and the Flying Carpet_算数基本定理
- LightOJ 1341 Aladdin and the Flying Carpet
- 【基本算术定理 && 质因数分解】LightOJ - 1341 Aladdin and the Flying Carpet
- LightOJ 1341 Aladdin and the Flying Carpet
- LightOJ-1341 Aladdin and the Flying Carpet 分解质因数(注意对大素数的优化)