zoj1154-Niven Numbers

来源:互联网 发布:优化方案答案物理答案 编辑:程序博客网 时间:2024/05/01 07:12

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=154

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<bitset>#include<stdlib.h>#include<iomanip> using namespace std;int main(){int sum , ans ;int Case ;int n ;char str[ 100 ] ;scanf( "%d" , &Case ) ;while( Case-- ){while(~scanf( "%d" , &n )){if( n == 0 )break ; scanf("%s" , str ) ;int len = strlen( str ) ;int temp = 1 ;sum = 0 ; ans = 0 ;for( int i = len - 1 ; i >=0 ; i-- ){sum += str[ i ] - '0' ;ans += temp * ( str[ i ] - '0' ) ;temp *= n ;}if( ans % sum == 0 )printf( "yes\n" ) ;elseprintf( "no\n" ) ;}if( Case != 0 )printf( "\n" ) ;}return 0 ;}


原创粉丝点击