3366: Help Mr Need Help

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:30 解决:0

题目描述

As an acmer, Mr Need Help always submits his solutions on Online Judge.However,his programs can not always get an "Aceept" because of  many strange reasons.And followed is his C/C++/Java solution for a problem.These 3 programs are of the same algorithm.

It his C source code:

#include<stdio.h>

int main()

{

    long long n,x,z,k,b;

    while(EOF!=scanf("%lld%lld%lld%lld%lld",&n,&x,&z,&k,&b))

    {

         long long first,second,tmp2=1%z,third=1%z,tmp3=x%b,i;

         for(first=n-1;n%first!=0;--first)

             ;

         for(second=0;second<z&&tmp2!=k%z;++second)

            tmp2=tmp2*x%z;

         for(i=1;i<=n;++i,tmp3=tmp3*x%b)

             third=third*tmp3%b;

         printf("%lld %lld %lld\n",first,second,third);

    }

    return 0;

}

It his C++ source code:

#include<iostream>

using namespace std;

int main()

{

    long long n,x,z,k,b;

    while(cin>>n>>x>>z>>k>>b)

    {

         long long first,second,tmp2=1%z,third=1%z,tmp3=x%b;

         for(first=n-1;n%first!=0;--first)

             ;

         for(second=0;second<z&&tmp2!=k%z;++second)

            tmp2=tmp2*x%z;

         for(int i=1;i<=n;++i,tmp3=tmp3*x%b)

             third=third*tmp3%b;

         cout<<first<<" "<<second<<" "<<third<<endl;

    }

    return 0;

}

It his Java source code:

import java.util.*;

public class Main

{

       public static void main(String[] args)

       {

              Scanner cin=new Scanner(System.in);

             long n,x,z,k,b;

             while(cin.hasNext())

             {

                  n=cin.nextLong();

                  x=cin.nextLong();

                  z=cin.nextLong();

                  k=cin.nextLong();

                  b=cin.nextLong();  

                  long first,second,tmp2=1%z,third=1%z,tmp3=x%b;

                  for(first=n-1;n%first!=0;--first)

                         ;

                  for(second=0;second<z&&tmp2!=k%z;++second)

                     tmp2=tmp2*x%z;

                  for(long i=1;i<=n;++i,tmp3=tmp3*x%b)

                     third=third*tmp3%b;

                  System.out.println(first+" "+second+" "+third);

             }

       }

}

 

For all the input data,Mr Need Help's programs get the right answer.However,any fool but Mr Need Help knows that these programs will cost too much time and surely an "Time Limit Exceed" is expected. 

Mr Need Help turned to you for help.Your task is to help Mr Need Help solve this problem.

输入

Just as Mr Need Help's programs show.What's more,n,x,z,k,b are integers and 2<=n<=254,1<=x<=109,1<=z<=109,0<=k<=109,1<=b<=106.

输出

Just an Mr Need Help's programs show.See the sample output for further details.

样例输入 复制

1729 4 4 0 883883
294409 3 4 2 9493

样例输出 复制

247 1 221134
7957 4 7492

来源/分类