hdu 5475 An easy problem

Problem Description
One day, a useless calculator was being built by Kuros. Let’s assume that number X is showed on the screen of calculator. At first, X = 1. This calculator only supports two types of operation.
1. multiply X with a number.
2. divide X with a number which was multiplied before.
After each operation, please output the number X modulo M.

Input
The first line is an integer T(1≤T≤10), indicating the number of test cases.
For each test case, the first line are two integers Q and M. Q is the number of operations and M is described above. (1≤Q≤105,1≤M≤109)
The next Q lines, each line starts with an integer x indicating the type of operation.
if x is 1, an integer y is given, indicating the number to multiply. (0

#include<stdio.h>
#include<string.h>
#define ll long long
ll a[555555];
int main()
{
   int t;
   scanf("%d",&t);
   int c=1;
   while(t--)
   {
       int n;
       ll m;
       scanf("%lld%lld",&n,&m);
       ll ans=1;
       printf("Case #%d:\n",c++);
       for(int i=1;i<=n;i++)
       {
           int z;
           scanf("%d %lld",&z,&a[i]);
           if(z==1)
           {
               ans=ans*a[i]%m;
           }
           else
           {
               a[a[i]]=1;
               a[i]=1;
               ans=1;
               for(int j=1;j<i;j++)
                ans=ans*a[j]%m;
           }
           printf("%lld\n",ans);
       }

   }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值