X-man

导航

爱情测试

http://ch.vijos.org/Contest/%E7%99%BD%E8%89%B2%E6%83%85%E4%BA%BA%E8%8A%82%E6%AC%A2%E4%B9%90%E8%B5%9B%20-%20Day1(Easy)/Problem/Show/%E7%88%B1%E6%83%85%E6%B5%8B%E8%AF%95

#include<stdio.h>
const long long mod=100007;
long long multy(long long q, long long n)
{
    long long cnt = n;
    long long base = q;
    long long ret = 1;
    while(cnt > 0)
    {
        if(cnt & 1)
            ret = (long long)ret*base%mod;
        cnt = cnt >> 1;
        base = (long long)base*base%mod;
    }
    return ret;
}
int main()
{
    long long a1,a2,a3,n,sum,q;
    while(scanf("%lld %lld %lld %lld",&a1,&a2,&a3,&n)!=EOF)
    {
        if(a3-a2==a2-a1)
            printf("%lld\n",( a1 + ((n-1)%mod) * ((a3-a2)%mod) )%mod);
        else
        {
            a1%=mod;
            q=a3/a2%mod;
            printf("%lld\n",a1*multy(q,n-1)%mod);
        }
    }
    return 0;
}

 

posted on 2013-05-07 21:52  雨钝风轻  阅读(222)  评论(0编辑  收藏  举报