1 solutions
-
0
C++ :
#include <cstdio> #include <iostream> #include <cmath> #include <algorithm> #include <cstring> #include <vector> #include <string> #define maxn 40000 using namespace std; long long c[62][62]; void initc() { int i,j; for (i=0;i<=60;i++) for (j=0;j<=i;j++) { if (!j||i==j) c[i][j]=1; else c[i][j]=c[i-1][j-1]+c[i-1][j]; } return; } long long gcd(long long a,long long b) { if(b==0) return a; return gcd(b,a%b); } long long exgcd(long long a,long long b,long long &x,long long &y) { if(b==0) { x=1; y=0; return a; } long long ans=exgcd(b,a%b,x,y); long long tmp=x; x=y; y=tmp-a/b*y; return ans; } int main() { //freopen("test.in","r",stdin); //freopen("test.out","w",stdout); initc(); long long m,a,b; while(scanf("%lld%lld%lld",&m,&a,&b)!=EOF) { if(m==0 && a==0 && b==0) break; if((m-1)%gcd(a,b)!=0) { printf("dead\n"); continue; } long long x,y,g=gcd(a,b); long long cc=(m-1)/g; a/=g,b/=g; exgcd(a,b,x,y); x*=cc; x%=b; y=(cc-a*x)/b; while(x<0||y>0) { x+=b; y=(cc-a*x)/b; } y*=-1; printf("%lld\n",c[x+y][y]); } return 0; }
- 1
Information
- ID
- 19301
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- (None)
- # Submissions
- 0
- Accepted
- 0
- Uploaded By