Character constant default type pit

When doing poj 2155 , we need to calculate 2^k, so I naturally think of using bit operation: 1<<k, but WA, because I use long long,

#include<cstdio>
using namespace std;
typedef long long ll;
ll exgcd(ll a,ll b,ll &x,ll& y){
    if(b==0) { x=1;y=0; return a;}
    ll tmp=exgcd(b,a%b,y,x);
    y-=x*(a/b);
    return tmp;
}
int main(){
    ll A,B,C,k;
    while(scanf("%lld%lld%lld%lld",&A,&B,&C,&k)==4){
        if(A==0&&B==0&&C==0&&k==0) break;
        ll b=(ll)1<<k,a=C,x,y;
        ll c=((B-A)%b+b)%b;
        ll d=exgcd(a,b,x,y);
        if(c%d) printf("FOREVER\n");
        else {
            ll ans=(c/d)*x;
            b/=d;
            ans=((ans%b)+b)%b;
            printf("%lld\n",ans);
        }
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324861715&siteId=291194637