比赛 20110412 评测结果 WWWEEETTTW
题目名称 双亲数 最终得分 0
用户昵称 fanzeyi 运行时间 0.000 s
代码语言 C 内存使用 0.00 MiB
提交时间 2011-04-12 10:21:02
显示代码纯文本
/*
 * =====================================================================================
 *
 *       Filename:  parents.c
 *
 *    Description:  20110412 Parents 双亲数
 *
 *        Version:  1.0
 *        Created:  2011年04月12日 00时50分14秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Zeray Rice , fanzeyi1994[at]gmail.com
 *        Company:  Fanhe.org
 *
 * =====================================================================================
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	FILE *fin=fopen("parents.in", "r");
	FILE *fout=fopen("parents.out", "w");
	int a, b, d;
	int i, j;
	int ma, mb;
	register int result = 0;
	short **array;
	fscanf(fin, "%d %d %d", &a, &b, &d);
	ma = a / d;
	mb = b / d;
	if( mb > ma )
	{
		ma ^= mb;
		mb ^= ma;
		ma ^= mb;
	}
	array = (short**)calloc(ma+1, sizeof(short*));
	for( i = 0 ; i <= ma ; i++ )
		array[i] = (short*)calloc(mb+1, sizeof(short));		
	for( i = 1 ; i <= ma ; i++ )
	{
		for( j = 1 ; j <= mb ; j++ )
		{
			if( j == 1 || i == 1 )
			{
				array[i][j] = 1;
				continue;
			}
			if( j == i )
				continue;
			if( i % j != 0 )
			{
				if( i <= mb )
				{
					array[i][j] = 1;
					array[j][i] = 1;
				}else{
					array[i][j] = 1;
				}
			}
		}
	}
	for( i = 1 ; i <= ma ; i++ )
	{
		for( j = 1 ; j <= mb ; j++)
			if( array[i][j] == 1 )
				result++;
	}
	fprintf(fout, "%d", result);
	return 0;
}