You are not logged in. Please login at www.codechef.com to post your questions!

×

CCFY - EDITORIAL

PRACTICE

CONTEST

Author- Medha Pandey

Tester- Akanksha Bigasia

Editorialist- Sanya Tayal

DESCRIPTION

Given an integer N find the GCD for for calculating rows to arrange chocolates in N number of stocks having particular number of choclates arranged in x number of rows.

EXPLANATION :

Calculate GCD for N number of stocks for all natural numbers from 1 to N. Run a loop from 1 to N and number of rows would be sum of all possible numbers for GCD. Final answer is x .

CODE:


int gcd(int a, int b) { if(a % b==0) return b; //to calculate GCD return gcd(b,a % b); } int div[1000001], p, exp; long long f1[1000001],f2[1000001],aux,pow; int main() { memset(div,-1,sizeof(div)); for(int i = 2;i< =1000000;++i){ if(div[i]==-1) { div[i] = i; if(i< =1000) for(int j = i * i;j< =1000000;j += i) div[j] = i; } } memset(f2,-1,sizeof(f2)); f11 = 0; f21 = 1; for(int i = 2;i< =1000000;++i) { p = div[i]; exp = 0; aux = i; pow = 1; while(aux%p==0) { pow * = p; ++exp; aux /= p; } f2[i] = ((exp+1) pow-exp (pow/p))* f2[aux]; f1[i] = f1[i-1]+f2[i]-i; } int N; while(true){ scanf("%d",&N); if(N==0) break; printf("%lld\n",f1[N]); }

asked 03 Apr '16, 00:28

ma14ab03_1995's gravatar image

2★ma14ab03_1995
163
accept rate: 0%

edited 16 May '16, 14:16

admin's gravatar image

0★admin ♦♦
19.8k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,678
×1,672
×319
×36
×13

question asked: 03 Apr '16, 00:28

question was seen: 1,613 times

last updated: 16 May '16, 14:16