|
发表于 2021-8-9 00:15:42
|
显示全部楼层
- #include <stdio.h>
- #include <math.h>
- int count = 0;
- int main1(void)//count = 648974546
- {
- int i, result=1;
- int limit = 20, flag;
-
- //printf("上限:");
- //scanf("%d", &limit);
-
- while(1){
- for(i=1;i<=limit;i++)
- {
- count += 1;
- if(result%i != 0){
- result += 1;
- break;
- }
- if (i == limit){
- flag = 1;
- }
- }
- if (result % limit == 0 && flag){
- break;
- }
- }
- printf("result = %d\n", result);
- printf("count = %d\n", count);
- return 0;
- }
- int is_prime(int value)
- {
- int i;
- for(i=2;i<=sqrt(value);i++)
- {
- count += 1;
- if (i>3) i++;//step 1
- if (value % i == 0) return 0;
- }
- return 1;
- }
- int find_step(int value)// step 2
- {
- int result = 1;
- int i,j;
- for(i=2;i<=value;i++)
- {
- count += 1;
- if (is_prime(i)){
- result *= i;
- }
- }
- return result;
- }
- int is_multiply(int value, int limit)
- {
- int i;
- for(i=1;i<=limit;i++)
- {
- count += 1;
- if (value%i!=0) return 0;
- }
- return 1;
- }
- int main(void) // count = 212
- {
- int i = 1;
- int limit = 20;
- int step = find_step(limit);
-
- while(!is_multiply(step * i, limit)) i++;
- printf("result = %d\n", step * i);
- printf("count = %d\n", count);
- }
复制代码 |
|