1. 程式人生 > >UVA 10127 - Ones(數論)

UVA 10127 - Ones(數論)

uil uri 數字 hit main play ica new get

UVA 10127 - Ones

題目鏈接

題意:求出多少個1組成的數字能整除n
思路:一位位去取模。記錄答案就可以
代碼:

#include <stdio.h>
#include <string.h>

int n;

int main() {
    while (~scanf("%d", &n)) {
    int ans = 1;
    int now = 1;
    while (now) {
        now = (now * 10 + 1) % n;
        ans++;
    }
    printf("%d\n", ans);
    }
    return
0; }

UVA 10127 - Ones(數論)