int main() { /*FOR( i, 1, 1000 ) FOR( j, 1, 1000 ) { int ij = droot( i * j ); int kk = droot( droot(i) * droot(j) ); if ( ij != kk ) printf( "droot(%d, %d) = %d, not %d\n", i, j, ij, kk ); } */ scanf( "%d", &T ); while ( T-- ) { scanf( "%d", &N ); #warning READ LLD REP( i, N ) scanf( "%I64d", &val[i] ); int64 ans = droot( val[N - 1] ); REPD( i, N - 1 ) ans = droot( droot(val[i]) * droot(ans+1) ); printf( "%I64d\n", ans ); } return 0; }
int droot( int x ) { if ( x < 10 ) return x; int ans = 0; while ( x > 0 ) { ans += x % 10; x /= 10; } return droot( ans ); }
void Conditions::setupDataRoot( void ) { DataRootSelect = new QFileDialog; DataRootSelect->setFileMode( QFileDialog::Directory ); connect( DataRoot, SIGNAL( textChanged( const QString & ) ), this, SIGNAL( newDataRoot( const QString & ) ), Qt::UniqueConnection ); if ( DataRoot0 != "" ) { // DataRoot の指定があった QFileInfo droot( DataRoot0 ); if ( droot.exists() ) { // 指定された名前があった if ( !droot.isDir() ) { // 指定された名前がファイルだった (ディレクトリではなかった) DataRoot0 = ""; // 指定は無かったことにする } } else { // 指定された名前が無のディレクトリを作るように努力する QDir newdir; if ( ! newdir.mkpath( DataRoot0 ) ) { // 作れなかったら DataRoot0 = ""; // 指定は無かったことにする } } } if ( DataRoot0 == "" ) { // 上の if の中で DataRoot0="" にする可能性があるので改めて訊く DataRoot0 = QDir::currentPath(); } DataRootSelect->setDirectory( DataRoot0 ); DataRoot->setText( DataRoot0 ); // この signal で newDataRoot を呼ぶ // EditDFName->setText( QFileInfo( DataRoot0, EditDFName->text() ).filePath() ); connect( SelDataRoot, SIGNAL( clicked() ), DataRootSelect, SLOT( show() ), Qt::UniqueConnection ); connect( DataRootSelect, SIGNAL( directoryEntered( const QString & ) ), DataRoot, SLOT( setText( const QString & ) ), Qt::UniqueConnection ); }