11417 - GCD
Problem A
GCD
Input: Standard Input
Output: Standard Output
Given the value of N, you will have to find the value of G. The definition of G is given below:
|
|
Here GCD(i,j) means the greatest common divisor of integer i and integer j.
For those who have trouble understanding summation notation, the meaning of G is given in the following code:
|
G=0; for(i=1;i<N;i++) for(j=i+1;j<=N;j++) { G+=GCD(i,j); } /*Here GCD() is a function that finds the greatest common divisor of the two input numbers*/ |
Input
The input file contains at most 100 lines of inputs. Each line contains an integer N (1<N<501). The meaning of N is given in the problem statement. Input is terminated by a line containing a single zero. This zero should not be processed.
Output
For each line of input produce one line of output. This line contains the value of G for corresponding N.
Sample Input Output for Sample Input
|
10 100 500 0
|
67 13015 442011 |
#include<stdio.h>
int gcd(int a, int b)
{
if(!b) return a;
return gcd(b,a%b);
}
int main()
{
int n;
while (scanf("%d",&n)&&n)
{
int g=0,i,j;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
g+=gcd(j,i);
printf("%d\n",g);
}
return 0;
}
11417 - GCD的更多相关文章
- uva 11417 - GCD
GCDInput: Standard Input Output: Standard Output Given the value of N, you will have to find the val ...
- Zerojudge解题经验交流
题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...
- Objective-C三种定时器CADisplayLink / NSTimer / GCD的使用
OC中的三种定时器:CADisplayLink.NSTimer.GCD 我们先来看看CADiskplayLink, 点进头文件里面看看, 用注释来说明下 @interface CADisplayLin ...
- iOS 多线程之GCD的使用
在iOS开发中,遇到耗时操作,我们经常用到多线程技术.Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法,只需定义想要执行的任务,然后添加到适当的调度队列 ...
- 【swift】BlockOperation和GCD实用代码块
//BlockOperation // // ViewController.swift import UIKit class ViewController: UIViewController { @I ...
- 修改版: 小伙,多线程(GCD)看我就够了,骗你没好处!
多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提升整体处理性能.具有这种能力的系 ...
- GCD的相关函数使用
GCD 是iOS多线程实现方案之一,非常常用 英文翻译过来就是伟大的中枢调度器,也有人戏称为是牛逼的中枢调度器 是苹果公司为多核的并行运算提出的解决方案 1.一次性函数 dispatch_once 顾 ...
- hdu1695 GCD(莫比乌斯反演)
题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...
- hdu2588 GCD (欧拉函数)
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数. (文末有题) 知 ...
随机推荐
- mysql 存在该记录则更新,不存在则插入记录的sql
转 http://www.cnblogs.com/zeroone/articles/2298929.html , ‘yourname') ON DUPLICATE KEY UPDATE auto_na ...
- 表单提交中get与post的区别
在Form里面,可以使用post也可以使用get.它们都是method的合法取值. 1. get是从服务器上获取数据,post是向服务器传送数据. 2. get是把参数数据队列加到提交表单的ACT ...
- PHP获取毫秒时间戳
我们知道,PHP中time()函数获取的时间戳,其单位是秒. 但是,前端JS获取的时间戳,单位是毫秒. 那么,在实际应用中,如何将JS和PHP的时间戳统一,即如何使用PHP获取毫秒时间戳呢,请看下例: ...
- 安装程序时出现错误代码0x80070422
通过win10应用商店,下载应用,安装时出现错误代码0x80070422. 需要打开services.msc,将windows update服务打开.
- Oracle EBS-SQL (WIP-11):检查期间任务完工记录数.sql
select WE.WIP_ENTITY_NAME 任务名称, WDJ.class_code ...
- 论山寨手机与Android联姻 【9】SmartPhone的硬件结构
如何区别智能手机(SmartPhone)与功能手机(FeaturePhone)? 有一种观点认为,智能手机本质上是功能手机与便携式电脑(Laptop PC)的结合.功能手机的功能受限于制造厂商的预制, ...
- UVA1292-----Strategic game-----树形DP解决树上的最小点覆盖问题
本文出自:http://blog.csdn.net/dr5459 题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&a ...
- Linux下 fcntl 函数用法说明
功能描述:根据文件描述词来操作文件的特性. 文件控制函数 fcntl -- file control LIBRARY Standard C Library (libc, ...
- #include <limits.h>
limits.h专门用于检测整型数据数据类型的表达值范围. #include<stdio.h> #include<limits.h> main() { printf(" ...
- express4.0之后不会解析req.files,必须加一个插件multer
express 4 + 用multer express4.0之后不会解析req.files,必须加一个插件multer http://www.w3school.com.cn/tags/att_form ...
