```// subject 49： The teacher divided the candy into several parts , Ask the students to collect it in any order , The first to receive , obtain 1 With the rest of the candy 1/10,
// The second one is , obtain 2 With the rest of the candy 1/10, The third one gets , obtain 3 With the rest of the candy 1/10, And so on ,
// How many students are there , How many sweets
#include<stdio.h>
#include<stdlib.h>
// Ideas ： The requirement of this problem is to find a quantity of candy , This amount must ensure that each student receives the whole number of candy , Not all students are required to score the same candy
// Define variables according to multiple variables , Simplify the operation difficulty rule , Defined as x A student ,y Sweets
// By listing , Find out the rules ：
//1+(y-1)*(1/10) The number of sweets the first student received
// Abstract functions
//f(1)=1+(y-1)*(1/10)
// Because every student gets the whole candy , therefore (y-1)*(1/10) Is an integer , explain y-1 yes 10 Multiple
// that y=10n+1
// By enumerating, we can get y The number of
// Define a variable last, To store the rest of the candy , Until last=0 until
// for the first time last=y- The number of sweets the first student received , namely last=y-1-(y-1)*(1/10) --- During enumeration y It's a known quantity
// The second time last=last- The number of sweets the second student received , namely last=last-（2+（last-2）*(1/10)）
// You need to make sure that last-2 yes 10 Multiple , namely (last-2)%10==0, Don't meet this condition , The number of apples is about to change
//y=10n+1 take n++
// It also needs to be last>0
// When last==0 when , Get the normal number of students and candy
// When last<0 when , It means that the quantity of candy is not normal , Need to put n++ , Cycle again
// third time lats=last- The number of sweets the third student received , namely last=last-（3+（last-3）*(1/10)）
// Uncertain number of cycles , Use while loop
void main(){
// Define the self increasing variable
int n = ;
// Define the amount of candy left each time
int last = * n + ;
// Define the number of students
int index = ;
while (){
// When there's no cycle at all , The remaining candy is equal to the total candy
// Start the cycle
// For the first time
// The number of apples left must be 10 Multiple
if ((last - index)%!=)
{
// This shows that the total number of candy does not meet all the conditions
n++;
// Initialize all data
last = * n + ;
index = ;
// So let's do the next loop
continue;
}
last = last - (index + (last - index)/);
if (last == )
{
// It shows that the total quantity of candy meets all the conditions
break;
}
else if (last>)
{
index++;
}
else{
// This shows that the total number of candy does not meet all the conditions
n++;
// Initialize all data
last = * n + ;
index = ;
// So let's do the next loop
continue;
}
if (n>)
{
printf(" It seems that the code I wrote has gone wrong ！\n");
break;
}
}
if (index!=)
{
printf(" Altogether %d A student , There are a total of %d Share \n", index, * n + );
}
system("pause");
}``` ```// subject 50： Kindergartens give candy to students from the front to the back , Each student gets candy in an arithmetic sequence , The sum of the first four students who got candy was 26, Product is 880,
// Seek before 20 The number of candies for each student
#include<stdio.h>
#include<stdlib.h>
// Ideas ： Before finding out 20 A student's candy , You have to know the difference between a student's candy and the equal difference
//a1+a2+a3+a4=26, because a2=a1+d,a3=a1+(3-1)d; namely 4a1+d+2d+3d=26;=>4a1+6d=26
//a1*a2*a3*a4=880;a1*(a1+d)*(a1+2d)*(a1+3d)=880
// Candy is a positive integer , therefore 4a1+6d=26( namely 2a1+3d=13),a1 and d It's all integers , therefore a The range is 0<a1<7;0<d<5
// So use a double loop
void main(){
int a[] = { };
int d = ;
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
if (*j + *i == )
{
if (j*(j + i)*(j + *i)*(j + *i) == )
{
a[] = j;
d = i;
break;
}
continue;
}
}
}
for (int i = ; i < ; i++)
{
if (i==)
{
printf("%5d", a[i]);
}
else{
a[i] = a[] + i*d;
printf("%5d", a[i]);
}
}
system("pause");
}
// summary ： This problem is an exercise, is to solve the binary equation programming solution , The key of binary equation programming is to determine the range of two elements , Find out the result by exhaustive method ,
// Good programming is to narrow down the scope of two elements , The scope of the problem element can be smaller ,2a1+3d=13,a１=6 In fact, it doesn't meet the requirements , Because at this time 3d=1,d It can't be an integer ``` ```// subject 51： Two different natural numbers A and B, If the whole number A All the factors of ( Include 1, barring A In itself ) The sum is equal to B;
// And integers B All the factors of ( Include 1, barring B In itself ) The sum is equal to A, Then the integer A and B It's called intimacy number . seek 10000 All intimacy numbers within .
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
// Ideas ： First, find a number A All the factors of , And then the sum of the factors , Get the number B, Number of judgements B Is the scope of 10000 within ,
// To find out B Is the sum of the factors equal to A
// Find all the factors of a number Find the number first A The square root of , And then we can find out all the factors by the method of circulation
int run1(int num){
int a = (int)sqrt((double)num)+;
int sum = ;
for (int i = ; i < a; i++)
{
if (num%i==)
{
sum = sum + i + num / i;
//sum += i;
}
}
return sum;
}
void main(){
int a[] = { };
int index = ;
int temp = ;
for (int i = ; i < ; i++)
{
// Acquisition number A The sum of the factors
temp = run1(i);
// Number of judgements B The scope of the
// Greater than required A, And in 10000 within , And count A It's not a number B
if (temp<i||temp>||(temp==i))
{
continue;
}
// Find the number B The sum of the factors
if (i == run1(temp))
{
printf("%d==>%d\n",i,temp);
}
}
system("pause");
}
// summary ： The difficulty of this problem is to find the number A Factor of , The key is to shrink A The range of factors (int)sqrt((double)num)+1``` ## C Language battle-hardened 17 More articles about

1. C Language battle-hardened 19

/* subject 55: There is a string that matches the following characteristics (”abcdef,acccd,eeee,aaaa,e3eeeee,sssss,";), Ask to write a function ( Interface ), Output the following results 1) Split strings with commas , ...

2. C Language battle-hardened 6

// subject 16: Enter two positive integers m and n, Find the greatest common divisor and the least common multiple . #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include< ...

3. C Programming language exercises 1-7

practice 1-7 Write a print EOF The value of the program . #include <stdio.h> // Contains information about the standard library . int main() // Definition is named main Function of , It doesn't accept parameter values . { // ...

4. C Language foundation (17)- Scope

One C The scope of a language variable can be a code block   Scope , Function scope or file scope . Writing is not recommended int a; //  There is the ambiguity of grammar , It could be a statement, it could be a definition , So it's better to declare after the definition is finished void func();  ...

5. C Language battle-hardened 3

// subject 7: use * No. 1 outputs a hollow diamond pattern #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> # ...

6. C Language battle-hardened 2

// subject 4: Enter the date of the year , Judge the day as the day of the year ? #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<st ...

7. C Language battle-hardened 1

// subject : Yes 1.2.3.4 A digital , How many different and unrepeated three digit numbers can be formed ? How many are they ? #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> ...

8. C Language battle-hardened 18

// subject 52: Print the following graph recursively //* //*.*. //*..*..*.. //*...*...*...*... //*....*....*....*....*.... #include<s ...

9. C Language battle-hardened 16

// subject 46: There is a pile of peaches on the beach , Five monkeys to share . The first monkey divided the pile of peaches into five parts , One more. , This one // The monkey threw one more into the sea , Took a share of . The second monkey divided the remaining peaches into five parts on average , Many more // One , It also puts ...

## Random recommendation

1. Give Way IE6 IE7 IE8 IE9 IE10 IE11 Support Bootstrap Solutions for

First of all, you need to make sure your HTML The beginning of the page should have DOCTYPE Statement .DOCTYPE Tell the browser what to use HTML or XHTML Specification HTML file , It will affect : To mark attributes .propertie ...

2. P1835 Prime density _NOI Guide 2011 Improve （04）

Title Description Given the interval [L,R](L≤R≤2147483647,R-L≤1000000), Please count the number of primes in the interval . I / O format Input format : Two Numbers L and R. Output format : a line , The number of primes in an interval . Input and output ...

3. HTML- Regular expressions

Commonly used HTML Regular expressions       1. You can only input numbers and English :       <input onkeyup="value=value.replace(/[\W]/g,'') "  ...

4. C# Web Api Upload files

One . Use the default method to upload files : 1.Action: /// <summary> /// Upload files Use the default file name after upload /// The default name is BodyPart_XXXXXX,BodyPart ...

5. angularJS FAQ summary

Problem description Solution When you insert a simple dynamic page html when , here html with angular The syntax of will not execute . var uploadInfo = ' Upload successful !<a ng-click="qu ...

6. Sublime Text Personalization

Personalized formatting code shortcuts Other shortcut key settings are similar , But be careful not to conflict with the shortcut keys of the software choice Preferences, Click on Key Bingdings - User Add... To the open file , among ctrl+alt+sp ...

7. codeforces 652C Foe Pairs Water problem

The question : Here are some pairs of numbers , Give you a sequence , Ensure that the numbers in the pair are in the sequence For this sequence , Ask how many intervals there are , Not including these pairs of numbers analysis : And then we turn these pairs of numbers into intervals , And then sort these intervals , And then scan it , Just record the right most left end ...

8. be based on visual Studio2013 solve C One of the questions in the language contest 0707 Monthly output

﻿﻿ subject Solution code and comments /* Make a program , Enter the month number , Output the English name of the month . for example , Input "3", The output "March", Requires pointer array processing . */ #includ ...

9. The safest so far MySQL？ Count in detail 5.7 Those amazing and chicken like new features （ On ）【 Reprint 】

from : DBAplus community http://www.toutiao.com/m5762164771/ The safest so far MySQL? Count in detail 5.7 Those amazing and chicken like new features ( On ) - Today's headline (TouTiao.com ...

10. front end css Something to add

Coding format @charset "utf-8"; body The outer margin setting of margin:0; Label settings form,ul,ol,li Set to padding:0; ul,ol,li Set to lis ...