练习赛20180428.Sign in(快速幂)

G - Sign in

Time Limit: 1000 MS Memory Limit: 262144 KB

64-bit integer IO format: %lld , %llu Java class name: Main

[Submit] [Status]

Description

This is the easiest problem.

There is a binary string. If it’s divisible by 5, output "Yes!"(without quotes), otherwise output "No!" (without quotes)

Input

There are several cases.

The first line is an integer n (0 < n ≤ 100000) which is the length of the binary string.

The second line is the binary string.

Output

"Yes!" O"No!"

Sample Input

3

101

1

1

Sample Output

Yes!

No!

考点:快速幂

参考代码:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int mod=5;

int power(int a,long long b){
    int c=1;
    for(;b;b>>=1){
        if(b&1)c=(long long)c*a%mod;
        a=(long long)a*a%mod;
    }
    return c;
}

int main(){
    int n;
    while(cin>>n){
    char a[n+5];
    memset(a,0,sizeof(a));
    cin>>a;
    int ans=0;
    for(int i=n-1;i>=0;i--){
        ans+=(a[i]-'0')*power(2,n-1-i);
    }
        if(ans%5==0)cout<<"Yes!"<<endl;
        else cout<<"No!"<<endl;
    }
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值