UVa - 10780 - Again Prime? No Time.
2014-09-09 18:58
302 查看
分解质因数处理。
用数组a和b分别保存n!和m的质因子的次幂。
整数x可以整除y时, x的各个质因子的次幂对应小于y的质因子次幂。
所以if(i是n!的质因子) res=min(a[i] / b[i]);
用数组a和b分别保存n!和m的质因子的次幂。
整数x可以整除y时, x的各个质因子的次幂对应小于y的质因子次幂。
所以if(i是n!的质因子) res=min(a[i] / b[i]);
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorithm> #include <fstream> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <vector> #include <cmath> #include <iomanip> typedef long long LL; typedef unsigned long long LLU; using namespace std; vector<int> prime; int a[10000+10], b[10000+10]; void init() { prime.clear(); int a[10111]={0}; for(int i=2; i<=10000; i++) for(int j=i*i; j<=10000; j+=i) a[j]=1; for(int i=2; i<=10000; i++) if(!a[i]) prime.push_back(i); } void fun(int x, int *c) { int i=0; while(x!=1) { while(x%prime[i]==0) { c[prime[i]]++; x/=prime[i]; } i++; } } int main() { init(); int t, kase=0; cin>>t; while(t--) { int m, n; cin>>m>>n; cout<<"Case "<<++kase<<":"<<endl; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for(int i=1; i<=n; i++) fun(i, a); fun(m, b); int res=1e9; for(int i=1; i<=m; i++) if(b[i]) res=min(a[i]/b[i], res); if(res==1e9 || res==0) cout<<"Impossible to divide\n"; else cout<<res<<endl; } return 0; }
相关文章推荐
- UVA10780 - Again Prime? No Time.(分解质因子)
- 【UVa 10780】 Again Prime? No time.
- uva 10780 - Again Prime? No Time.(数论)
- uva 10780 Again Prime? No Time.
- UVa 10780 - Again Prime? No time (质因式分解)
- UVA 10780 - Again Prime? No Time.(数论)
- UVA 10780 Again Prime? No Time. ——质因分解
- Uva10780 Again Prime? No Time.
- uva10780 - Again Prime? No time
- [UVa 10780]Again Prime?No time.
- Uva 10780 Again Prime? No Time.(分解质因子)
- uva 10780 Again Prime? No Time. 质因子乱搞
- UVa 10780 Again Prime? No Time. (数论&素因子分解)
- UVa 10780 - Again Prime? No Time.
- UVA10780:Again Prime? No Time(数论)
- UVa 10780 (质因数分解) Again Prime? No Time.
- uva 10780 Again Prime? No Time.
- UVA 10780 Again Prime? No time
- UVA-10780-Again Prime? No Time(素数分解)
- UVA - 10780 Again Prime? No Time.