The Guo Jie of the NUC

Source: Internet
Author: User

Problem description

Guo Jie wants you to help him find the value of F.
Enter a description

Example of multi-group test sample.

A positive n (4<=n<=1e9) output description for each set of samples that is greater than 3

Each set of test sample output one row. (Results reserved 12 decimal places) sample input

4
Sample output
0.250000000000
SOURCE 12th session of the North University program design contest Tips

Hehe, secretly tell you, really white again in test Guo Jie Math ~

Ideas:

If the problem is calculated as equal to 4 and not equal to 4, then it will time out. So the main problem is to find 6/(n (n-1) * (n-2)) this law.

Timeout code:

#include <stdio.h>
#include <stdlib.h>/

* Run this program using the console Pauser or add your own GE TCH, System ("pause") or input loop *

/int main () {
	double n, sum = 1;
	int i;
	while (scanf ("%lf", &n)!=eof) {
		double A = n;
		if (n = = 4) {
			sum = 1.0 * 1.0/4;
			printf ("%.12f\n", sum);
		} else if (n>4) {for
			(i=1;i<n-3;i++) {
				sum *= i/a;
				a--;
			}
			printf ("%.12f\n", sum);
		
		}
		
	}
	return 0;
}


Correct code:

#include <stdio.h>
#include <stdlib.h>/

* Run this program using the console Pauser or add your own Getch, System ("pause") or input loop *

/int main () {
	double n, sum = 0;
	while (scanf ("%lf", &n)!=eof) {
		sum = 6/(n (n-1) * (n-2));
		printf ("%.12f\n", sum);
		
	}
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.