#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char input[20];
long n;
int result;
char *endptr;
long sum = 0;
long count = 0;
char str[100] = "";
fgets(input
, sizeof(input
), stdin
);
// 检查输入是否为空
if (input[0] == '\n') { // 如果输入的第一字符是换行符,说明输入为空
printf("\nError! No input provided.\n"); printf("Press any key to continue...\n"); return 1;
}
// 使用 sscanf 直接从输入字符串中提取第一个整数
result
= sscanf(input
, "%ld%n", &n
, &endptr
);
if (result == 1 && endptr >= input && *endptr == '\0') {
// 输入是一个有效的正整数
if (n > 0) {
for (long i = 1; i <= n; i++) {
if (i % 5 == 0 && i % 7 != 0) {
sum += i;
count++;
if (count == 1) {
} else {
}
}
}
printf("\n符合条件的数列和为: %s = %ld\n", str
, sum
); printf("Press any key to continue...\n"); } else {
printf("\nError! Input is not a positive integer.\n"); printf("Press any key to continue...\n"); }
} else {
printf("\nError! Invalid input format.\n"); printf("Press any key to continue...\n"); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKaW50IG1haW4oKSB7CiAgICBjaGFyIGlucHV0WzIwXTsKICAgIGxvbmcgbjsKICAgIGludCByZXN1bHQ7CiAgICBjaGFyICplbmRwdHI7CiAgICBsb25nIHN1bSA9IDA7CiAgICBsb25nIGNvdW50ID0gMDsKICAgIGNoYXIgc3RyWzEwMF0gPSAiIjsKCiAgICBwcmludGYoIuivt+i+k+WFpeS4gOS4quato+aVtOaVsDogIik7CiAgICBmZ2V0cyhpbnB1dCwgc2l6ZW9mKGlucHV0KSwgc3RkaW4pOwoKICAgIC8vIOajgOafpei+k+WFpeaYr+WQpuS4uuepugogICAgaWYgKGlucHV0WzBdID09ICdcbicpIHsgLy8g5aaC5p6c6L6T5YWl55qE56ys5LiA5a2X56ym5piv5o2i6KGM56ym77yM6K+05piO6L6T5YWl5Li656m6CiAgICAgICAgcHJpbnRmKCJcbkVycm9yISBObyBpbnB1dCBwcm92aWRlZC5cbiIpOwogICAgICAgIHByaW50ZigiUHJlc3MgYW55IGtleSB0byBjb250aW51ZS4uLlxuIik7CiAgICAgICAgZ2V0Y2hhcigpOwogICAgICAgIHJldHVybiAxOwogICAgfQoKICAgIC8vIOS9v+eUqCBzc2NhbmYg55u05o6l5LuO6L6T5YWl5a2X56ym5Liy5Lit5o+Q5Y+W56ys5LiA5Liq5pW05pWwCiAgICByZXN1bHQgPSBzc2NhbmYoaW5wdXQsICIlbGQlbiIsICZuLCAmZW5kcHRyKTsKCiAgICBpZiAocmVzdWx0ID09IDEgJiYgZW5kcHRyID49IGlucHV0ICYmICplbmRwdHIgPT0gJ1wwJykgewogICAgICAgIC8vIOi+k+WFpeaYr+S4gOS4quacieaViOeahOato+aVtOaVsAogICAgICAgIGlmIChuID4gMCkgewogICAgICAgICAgICBmb3IgKGxvbmcgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgICAgICAgICBpZiAoaSAlIDUgPT0gMCAmJiBpICUgNyAhPSAwKSB7CiAgICAgICAgICAgICAgICAgICAgc3VtICs9IGk7CiAgICAgICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgICAgICBpZiAoY291bnQgPT0gMSkgewogICAgICAgICAgICAgICAgICAgICAgICBzcHJpbnRmKHN0ciwgIiVsZCIsIGkpOyAvLyDnrKzkuIDkuKrmlbAKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJjYXQoc3RyLCAiICsgIik7IC8vIOa3u+WKoOWIhumalOespgogICAgICAgICAgICAgICAgICAgICAgICBzcHJpbnRmKHN0ciArIHN0cmxlbihzdHIpLCAiJWxkIiwgaSk7IC8vIOi/veWKoOS4i+S4gOS4quaVsAogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgcHJpbnRmKCJcbuespuWQiOadoeS7tueahOaVsOWIl+WSjOS4ujogJXMgPSAlbGRcbiIsIHN0ciwgc3VtKTsKICAgICAgICAgICAgcHJpbnRmKCJQcmVzcyBhbnkga2V5IHRvIGNvbnRpbnVlLi4uXG4iKTsKICAgICAgICAgICAgZ2V0Y2hhcigpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHByaW50ZigiXG5FcnJvciEgSW5wdXQgaXMgbm90IGEgcG9zaXRpdmUgaW50ZWdlci5cbiIpOwogICAgICAgICAgICBwcmludGYoIlByZXNzIGFueSBrZXkgdG8gY29udGludWUuLi5cbiIpOwogICAgICAgICAgICBnZXRjaGFyKCk7CiAgICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgICBwcmludGYoIlxuRXJyb3IhIEludmFsaWQgaW5wdXQgZm9ybWF0LlxuIik7CiAgICAgICAgcHJpbnRmKCJQcmVzcyBhbnkga2V5IHRvIGNvbnRpbnVlLi4uXG4iKTsKICAgICAgICBnZXRjaGFyKCk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=