G - Sign in
Time Limit: 1000 MS Memory Limit: 262144 KB
64-bit integer IO format: %lld , %llu Java class name: Main
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!" Or "No!"
Sample Input
3
扫描二维码关注公众号,回复:
1478766 查看本文章
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; } }