练习赛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;
    }
}


猜你喜欢

转载自blog.csdn.net/xxxxxm1/article/details/80292544