HDU 1299 Diophantus of Alexandria (maths problem)

Source: Internet
Author: User
Tags cas

Title Link: Hdu 1299 diophantus of Alexandria

Test instructions

Give you a n, let you find 1/x+1/y=1/n number of programs.

Exercises

For this kind of mathematical problem, generally change the deformation, find the law, by playing the table we can find that the answer is only related to the number of factors.

N=a1^p1*a2^p2*...*an^pn

Ans= ((1+2*P1) * (1+2*P2) *...* (1+2*PN) +1)/2

1#include <bits/stdc++.h>2 #defineF (I,A,B) for (int i=a;i<=b;++i)3 using namespacestd;4 5 Const intn=1e5+7;6 intprimes[n],tot=0;7 BOOLVis[n];8 voidEuler () {9F (I,2, N-7){Ten         if(!vis[i]) primes[++tot]=i; OneF (J,1, tot) { A             if(i*primes[j]>n) Break; -vis[i*primes[j]]=1; -             if(i%primes[j]==0) Break; the         } -     } - } -  + intT,n,ans,cas; -  + intMain () A { at Euler (); -scanf"%d",&t); -      while(t--) -     { -scanf"%d",&n); -ans=1; inF (I,1, tot) -         { to             if(primes[i]>n) Break; +             intCnt=0; -              while(n%primes[i]==0) n/=primes[i],cnt++; theans*=2*cnt+1; *         } $         if(n>1) ans*=3;Panax Notoginsengprintf"Scenario #%d:\n%d\n\n", ++cas, (ans+1)/2); -     } the     return 0; +}
View Code

HDU 1299 Diophantus of Alexandria (maths problem)

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.