题目描述

给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除。

输入描述:

两个整数n(2<=n<=1000),a(2<=a<=1000)

输出描述:

一个整数.
示例1

输入

复制

6 10

输出

复制

1
分解质因数取min即可;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-11
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int pme[maxn];
int tot;
int vis[maxn];
int cnt[maxn];
void init() {
for (int i = 2; i < maxn; i++) {
if (!vis[i]) {
pme[++tot] = i;
for (int j = i; j < maxn; j += i) {
vis[j] = 1;
}
}
}
}
int num[maxn]; int main() {
int n, a;
scanf("%d%d", &n, &a);
init();
for (int i = 1; i <= tot; i++) {
int tmp = n;
while (tmp) {
cnt[pme[i]] += tmp / pme[i]; tmp /= pme[i];
}
}
int minn = 999999;
/* for(int i=1;i<=tot;i++){
if(cnt[pme[i]]){
cout<<pme[i]<<' '<<cnt[pme[i]]<<endl;
}
}
*/
for (int i = 1; i <= tot; i++) {
while (a%pme[i] == 0) {
num[i]++; a /= pme[i];
}
}
for (int i = 1; i <= tot; i++) {
if(num[i])
minn = min(minn, cnt[pme[i]] / num[i]);
}
cout << minn << endl;
}

SJTU 机试 数学的更多相关文章

  1. SJTU 机试 最小面积子矩阵 压缩+双指针

    链接:https://www.nowcoder.com/questionTerminal/8ef506fbab2742809564e1a288358554来源:牛客网 一个N*M的矩阵,找出这个矩阵中 ...

  2. 【转】朱兆祺教你如何攻破C语言学习、笔试与机试的难点(连载)

    原文网址:http://bbs.elecfans.com/jishu_354666_1_1.html 再过1个月又是一年应届毕业生应聘的高峰期了,为了方便应届毕业生应聘,笔者将大学四年C语言知识及去年 ...

  3. java机试要点

    Java机试准备 一般结构:   import java.util.Scanner; public class Main{ public static void main(String[] args) ...

  4. 2015 NI 校招笔试机试面试

    美国国家仪器NI也算是入驻上海很好的一家外企了,它是我们院的合作公司,加上今年NI在我们院扩招实习生,这次是一个难得的机会可以进入NI实习,可惜我并没有好好把握... 一.笔试 几个做错的印象特别深刻 ...

  5. 华为 2015 机试 输出:数字后面的连续出现的(2个或多个)相同字符(数字或者字符),删去一个,非数字后面的不要删除,例如,对应输出为:33aabb55pin。

    package 华为机试; //C++ 输入:由数字和字母组成的字符串,例如:333aaabb55ppin //输出:数字后面的连续出现的(2个或多个)相同字符(数字或者字符),删去一个,非数字后面的 ...

  6. 华为OJ机试训练(一)

    题目1 -- 通过输入英文句子.将每一个单词反过来,标点符号顺序不变.非26个字母且非标点符号的情况就可以标识单词结束. 标点符号包含,.!? 比如输入:Hello, I need an apple. ...

  7. 2014华为机试西安地区B组试题

    2014华为机试西安地区B组试题 题目一.亮着点灯的盏数 一条长廊里依次装有n(1≤n≤65535)盏电灯,从头到尾编号1.2.3.-n-1.n.每盏电灯由一个拉线开关控制.開始,电灯所有关着. 有n ...

  8. 华为机试001:字符串最后一个单词的长度(华为OJ001)

    华为机试 字符串最后一个单词的长度 计算字符串最后一个单词的长度,单词以空格隔开. 提交网址: http://www.nowcoder.com/practice/8c949ea5f36f422594b ...

  9. web机试

    测试: <html><style> </style><title>Demo</title> <body><div > ...

随机推荐

  1. Objective-C 的 self 和 super 详解 (用简单程序说明问题)

    在 Objective-C 中的类实现中经常看到这两个关键字 "self" 和 "super",以以前 oop 语言的经验,拿 c++ 为例,self 相当于 ...

  2. shelve和hashlib模块

    一.shelve模块 shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式. 注意: shelve模块封装了pickle模块,,允许 ...

  3. 数据库与vs的连接

    新建一个MFC基于对话框的项目后,更改属性, 其中需要将include(里面都是MySQL的头文件)lib是库文件,将.dll放入与.exe同级目录下,或放入系统里(c:\windows\system ...

  4. 管理授权&管理决策&管理组织&管理目标

    [管理授权] 1.如果一个管理者不明白为公司培养人的责任,就很可能成为公司的瓶颈.这个问题的解决在于让管理者学会“授权”,把大部分自己紧抓不放的事情下放给部门内其他人做. 2.为一件事负责和亲自做是两 ...

  5. mfs监控

    web gui 监控 gui_info.jpg (143.72 KB, 下载次数: 83) gui_most.jpg (209.36 KB, 下载次数: 82) gui_master_info.jpg ...

  6. 面试题:SSH项目总结 !=!=未看 没用

    阿玻罗软件(上海)有限公司已经两年了.中国银行营销系统,到民生银行小微信贷工厂建设.再到交通银行ioffice移动平台项目.以前所学的SSH好多都用不上 公司的框架.都是负责项目的贷款查找模块开发和测 ...

  7. sql server 错误总结

    1>无法访问sql server2000数据库 1.1>安装sql server2000 sp1的补丁包. 1.2>sql server 数据库开启了允许远程访问. 1.3>s ...

  8. 数字图像处理实验(14):PROJECT 06-01,Web-Safe Colors 标签: 图像处理MATLAB 2017-05-27 20:45 116人阅读

    实验要求: Objective: To know what are Web-safe colors, how to generate the RGB components for a given jp ...

  9. git 的使用方法

    git 的使用有3个主要步骤: 1.1 工作区域操作: 在自己的git账号下构建一个工作目录, 并往工作目录里添加文件内容(cp /root/data/VIP_Amount_prediction/* ...

  10. python核心编程第4章课后题答案(第二版75页)

    4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with ...