You are not logged in. Please login at www.codechef.com to post your questions!

×

plz help....getting WA.....:(

I tried to figure out every test case covered .....but still getting wrong answer ....please point out my mistake .... this is the problem statement http://www.codechef.com/AUG13/problems/CHMOD

my solution http://pastebin.com/m5q83MhQ

asked 13 Aug '13, 01:41

vivek07672's gravatar image

2★vivek07672
15122124
accept rate: 0%

edited 15 Aug '13, 01:40


vivek07671..in your code this statement is wrong..

if(left==right) { for(int i=1;i<=100;i++) { ans=(ans*fast_exp(i,a[left][i]))%mod; //Wrong statement } }

Just try this input on your code

5

5 5 5 5 5

1

3 3 100

The answer should be 5 but your code will give 125... The correct statement is

ans=(ans*fast_exp(i,a[left][i]-a[left-1)[i])%mod;

link

answered 15 Aug '13, 13:00

vikasnitt's gravatar image

2★vikasnitt
67891626
accept rate: 9%

Try this test case:

3
2 2 2
2
1 3 5
1 3 1000000

It give 1 6 whereas the actual output is 3 8. Hope it helps.

link

answered 13 Aug '13, 23:27

sobhagya's gravatar image

3★sobhagya
2.7k132747
accept rate: 12%

I am not getting the missed test case .......

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long int fast_exp(long long int ,long long int );
int a[100001][101];
long long int mod;
int main()
{
    int n;
    scanf("%d",&n);
    int temp;
    for(int i=0;i<=100000;i++)
    {
        for(int j=0;j<=100;j++)
        {
            a[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=100;j++)
        a[i][j]=a[i][j]+a[i-1][j];
        scanf("%d",&temp);
        a[i][temp]++;

    }

    int left,right;

    int t;
    scanf("%d",&t);
     long long int ans;
     long long int x;
    while(t--)
    {
        ans=1;
        scanf("%d",&left);
        scanf("%d",&right);
        scanf("%d",&mod);
        if(left==right)
        {
            for(int i=1;i<=100;i++)
            {
                ans=(ans*fast_exp(i,a[left][i]))%mod;
                //ans=ans%mod;

            }

        }
        else{

        for(int i=1;i<=100;i++)
        {

           x=a[right][i]-a[left-1][i];

           if(x>0)
            {
            ans=(ans*fast_exp(i,x))%mod;
                 //ans=ans%mod;
                 //cout<<"jhfdvbjfd"<<ans<<"\n";

            }
            }

        }
        printf("%lld\n",ans);

    }
    return 0;
}

long long int fast_exp(long long int base, long long int exp) {
    long long int res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp/=2;
    }
    return res%mod;
}
/*
5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
4
1 2 3
2 3 4
1 1 1
1 5 1000000000
*/
link

answered 15 Aug '13, 01:26

vivek07672's gravatar image

2★vivek07672
15122124
accept rate: 0%

edited 15 Aug '13, 01:28

betlista's gravatar image

3★betlista ♦♦
16.9k49115225

Try using scanf("%lld",&mod); instead of scanf("%d",&mod);

The variable mod is declared as a long long int.

link

answered 15 Aug '13, 08:20

tijoforyou's gravatar image

2★tijoforyou
4.2k52364
accept rate: 15%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,070
×729
×47
×4
×1
×1

question asked: 13 Aug '13, 01:41

question was seen: 1,168 times

last updated: 15 Aug '13, 13:00