Title: Bio-chip
Dr. X is working on a biological chip. The Doctor has designed n miniature light sources in the chip, and each light source will change its state once it is switched on, that is, the light turns off, or turns the switch off to light.
These light sources are numbered from 1 to N, and all light sources are turned off at the beginning.
The doctor plans to perform the following actions on the chip:
All lights that are numbered in multiples of 2 are operated once, i.e. 2 4 6 8 ... Wait for the number light to open
All lights that are numbered in multiples of 3 are operated once, that is, 3 6 9 ... And so on the operation of the light source, note that at this point 6th light source is closed again.
All lights with a multiple of number 4 are operated once.
.....
The light is manipulated one time until a multiple of the number is N.
Dr X wants to know which light sources in an interval are lit after these operations.
"Input Format"
3 integers separated by spaces: N L R (l<r<n<10^15) n represents the number of lights, L represents the left boundary of the interval, and R represents the right boundary of the interval.
"Output Format"
Outputs 1 integers, indicating how many lights in the [l,r] interval are lit after all operations.
For example:
Input:
5 2 3
The program should output:
2
Again for example:
Input:
10 3 6
The program should output:
3
Resource contract:
Peak memory Consumption < 256M
CPU Consumption < 1000ms
Please strictly according to the requirements of the output, do not use the superfluous printing similar: "Please enter ..." Redundant content.
All the code is placed in the same source file, after debugging passed, the copy is submitted to the source.
Note: The main function needs to return 0
Note: Use only ANSI c/ansi C + + standards, and do not invoke special functions that depend on the compilation environment or operating system.
Note: All dependent functions must explicitly #include <xxx> in the source file, and the common header files cannot be omitted from the project settings.
When committing, be careful to choose the type of compiler you expect.
1#include <stdio.h>2#include <string.h>3#include <math.h>4 #defineN 9999995 intN,l,r;//n The number of light sources, the left and right boundary of the l\r table interval6 intG[n];7 intChangeinti) {8 if(i==0)9 return 1;Ten Else One return 0; A } - voidDigui (intYinintg[]) { - if(yin>n)return; the for(intI=1; i<=n;i++){ - if(i%yin==0){ -g[i-1]=change (g[i-1]); - } + } -Digui (yin+1, g); + } A intMain () { at intans=0;//number of lights at the end of the table -scanf"%d%d%d", &n,&l,&r);//Data Entry -Memset (G,0,sizeof(g));//The initial light is off -Digui (2, g); - for(inti=l;i<=r;i++){ - if(g[i-1]) ans++; in } -printf"%d", ans); to return 0; +}
C language · Bio-chip