【组合数】【Lucas】Number Theory Special Training T3 comb 题解

Problem 3. comb
Input file: comb.in
Output file: comb.out
Time limit: 1 second
Memory limit: 256 MB
一天,Mr. Hu 对组合数产生了兴趣,他想要知道满足下面条件的数i 有多少个:
gcd(
(
n
i
)
; p) = p (0 i n)
其中p 是素数。
Input
第1 行,2 个整数:n p。
Output
输出所求。
Sample
comb.in comb.out
5 2 1
Note
样例中,一共有5 个组合数:1; 5; 10; 5; 1,其中和2 公约数为2 的数只有一个10,故输出1。
• 对于30% 的数据,满足1 n; p 103
• 对于100% 的数据,满足1 n; p 1018
Page

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<stack>
#define INF 2100000000
#define LL long long
#define clr(x) memset(x,0,sizeof(x))
#define ms(a,x) memset(x,a,sizeof(x))
#ifdef WIN32
#define AUTO "%I64d"
#else
#define AUTO "%lld"
#endif

using namespace std;

int main() {
    freopen("comb.in","r",stdin);
    freopen("comb.out","w",stdout);
    LL n,p,ans1,ans2;
    scanf(AUTO""AUTO,&n,&p);
    ans1 = n+1; ans2 = 1;
    while(n) ans2 *= n%p+1, n /= p;
    printf(AUTO"\n",ans1-ans2-1);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值