| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
i try many times on this problem, but stil got wrong answer, anyone help me..In Reply To:Weird Posted by:ACMTino at 2006-09-30 02:25:22 i have tested many random data, and compared to a ACed pragram, but the result appeared the same, here is my code, many thanks.
#include<cstdio>
typedef long long llong;
int main()
{
int t,n,k,sm;
llong m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&k,&sm); m=sm;
llong o=1,base,ans=1;
for(base=10;k;k/=2,base=base*base%m)
if(k&1) o=o*base%m;
o=(o+1)%m;
for(base=o;n;n/=2,base=base*base%m)
if(n&1) ans=ans*base%m;
printf("%I64d\n",ans);
}
return 0;
}
> I suspected that Judge has some bug in it.
>
> if I change
> **************************************************
> t=n;
> count=0;
> while(n) {
> b[count++]=n%2;
> n/=2;
> }
> **************************************************
> to
> t=n;
> count=0;
> while(t) {
> b[count++]=t%2;
> t/=2;
> }
>
> it would get accepted
>
> please check it, thanks
> ACMTino
>
>
>
> #include<stdio.h>
> #include<stdlib.h>
>
> main() {
> __int64 i,j,cases;
> __int64 n,k,m,t,count,result;
> bool b[50];
>
> scanf("%I64d",&cases);
> while(cases--) {
> scanf("%I64d %I64d %I64d",&n,&k,&m);
>
> t=k;
> count=0;
> while(t) {
> b[count++]=t%2;
> t/=2;
> }
> t=10;
> result=1;
> for(i=0;i<count;++i) {
> if(b[i]) result=(result*t)%m;
> t=(t*t)%m;
> }
> result=(result+1)%m;
>
> t=n;
> count=0;
> while(n) {
> b[count++]=n%2;
> n/=2;
> }
>
> t=result;
> result=1;
> for(i=0;i<count;++i) {
> if(b[i]) result=(result*t)%m;
> t=(t*t)%m;
> }
> printf("%I64d\n",result);
> }
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator