2016-02-08 Problem Solving►UVa UVa 10127 - Ones Contents 1. Problem2. Solution3. Code Problem題目網址中文網址 Solution直接硬除會溢位,為了避免使用大數,從 1 開始,判斷 n 是否可整除它,如不行就將餘數乘10再加上1,然後繼續判斷,如此一來每次都只要處理2位數。 CodeUVa 10127UVa 10127 - Ones1234567891011121314151617181920212223#include<cstdio>int main(){ int n; while (scanf("%d", &n) != EOF) { int ans, now; int remainder = n == 1 ? 0 : 1;//每一次的餘數 for (ans = 1; remainder; ans++) { now = remainder * 10 + 1; remainder = now%n; } printf("%d\n", ans); } return 0;} Newer UVa 1124 - Celebrity jeopardy Older UVa 264 - Count on Cantor