Aladdin and the Flying Carpet LightOJ
来源:互联网 发布:如何用手机淘宝装修 编辑:程序博客网 时间:2024/05/16 01:32
题目链接
可以利用唯一分解定义求出有多少个约数,然后再减去小于b的.我直接求出了约数,然后计算,比较耿直~~
#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll INF = 1e18;const int N = 1000004;int isprime[1000005];int prime[1000005];int cnt = 0;void initprime(){ for(int i=2;i<N;i++) { isprime[i] = true; } for(int i=2;i<N;i++) { if(isprime[i]) { prime[++cnt]=i; for(int j=i<<1;j<N;j+=i) { isprime[j] = false; } } }}int T;int n;int ct[100005];int a[100005];ll b[100005];int num;int mid;ll aa,bb;int ans = 0;void dfs(int cur,ll x){ if(cur>=num) { if(x>=bb&&aa/x>=bb) { if(x==aa/x) return; ans++; } return ; } for(int i=0;i<=a[cur];i++) { ll tt = 1; for(int j=0;j<i;j++) { tt*=b[cur]; } dfs(cur+1,x*tt); }}int main(){// freopen("data.txt","r",stdin);// ios::sync_with_stdio(false); initprime(); cin >> T; for(int cas = 1;cas<=T;cas++) { ans = 0; memset(ct,0,sizeof(ct)); cin >> aa>>bb; ll tx = aa; int f = 1; while(tx!=1&&f) { f=0; for(int i=1;i<=cnt;i++) { if(tx%prime[i]==0) { ct[i]++; f=1; tx/=prime[i]; break; } } } num = 0; for(int i=1;i<=cnt;i++) { if(ct[i]) { a[num] = ct[i]; b[num] = prime[i]; num++; } } if(tx!=1) { a[num] = 1; b[num] = tx; num++; } dfs(0,1); cout <<"Case "<<cas<<": "<<ans/2<<endl; } return 0;}
阅读全文
0 0
- lightOJ 1341 Aladdin and the Flying Carpet
- LightOJ 1341 Aladdin and the Flying Carpet
- LightOJ 1341Aladdin and the Flying Carpet
- LightOJ 1341 - Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- LightOJ 1341 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- LightOJ-1314 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet
- 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【整数分解】
- python大作战之迭代器初级篇
- java基础-new String(byte[] b, int n, int m)
- 图像质量评估指标 SSIM / PSNR / MSE
- BZOJ4421
- 1-进程和线程的由来和区别
- Aladdin and the Flying Carpet LightOJ
- STM32之GPIO口
- git学习——Github关联(2)
- python多进程
- caffe实现多标签输入(multilabel、multitask)
- github fork源仓库后保持同步
- ABCNN代码注释
- 使用DataGrip连接SQL Server 2017数据库
- 2-Java中如何创建进程