LightOJ 1340 Story of Tomisu Ghost
来源:互联网 发布:淘宝发布宝贝类别 编辑:程序博客网 时间:2024/06/07 13:36
线性预处理出1~1e5的素数,nlogn的也可以
对于每组n,t,把n!质因数分解再贪心即可
还可以用下快速幂进行优化
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int MAXN = 1e5;const ll mod = 10000019;bool is_prime[MAXN + 5];vector<int> prime;void get_prime(){ memset(is_prime, true, sizeof(is_prime)); is_prime[0] = is_prime[1] = false; for(int i = 2; i <= MAXN; i++) { if(is_prime[i]) prime.push_back(i); for(int j = 0; j < prime.size() && i * prime[j] <= MAXN; j++) { is_prime[i * prime[j]] = false; if(i % prime[j] == 0) break; } }}ll fast_pow(ll x, int n){ ll res = 1; while(n) { if(n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res;}int cnt(int n, int p){ int res = 0; while(n) n /= p, res += n; return res;}ll solve(int n, int t){ ll res = 1; for(int i = 0; i < prime.size(); i++) { int p = prime[i], num = cnt(n, p); if(num < t) break; res = (res * fast_pow(p, num / t)) % mod; } if(res == 1) return -1; return res;}int main(){ int T; scanf("%d", &T); get_prime(); for(int ca = 1; ca <= T; ca++) { int n, t; scanf("%d%d", &n, &t); printf("Case %d: %lld\n", ca, solve(n, t)); } return 0;}
0 0
- LightOJ 1340 Story of Tomisu Ghost
- LightOJ 1340 - Story of Tomisu Ghost (求n!在b进制下末尾0)
- a story of 卓玛
- story of "Architect"
- a story of love
- The Story of today.
- story of winstone
- a story of Caching
- Story of ellepi
- THE STORY OF O
- story of 构造函数
- The Story of Creating Enterprises
- the story of new oriental
- love story of Isaac Newton
- Story of my programming life
- Outliers: The Story of Success
- SOJ 4265: story of 206
- The End-of-Line Story
- visual studio 2010编译器设置备注
- 怎么在程序内部确定程序自己的绝对路径(windows,linux)
- Unity3D之Animation中AnimationEvent的BUG?爬坑向
- WLAN控制器 - CAPWAP协议简介
- mybatis中的#和$的区别
- LightOJ 1340 Story of Tomisu Ghost
- 测试用例 自动生成工具PICT与AllPairs
- 看看Spring源码(二)——bean实例化
- 简单的欧几里德与扩展欧几里德
- jQuery $("")
- Android使用ShareSdk完成QQ和微信的分享功能
- linux 查看进程占用内存
- QT QPushButton点击事件的实现
- 快速Android开发系列网络篇之Android-Async-Http