immuntasir

UVA 10699

Feb 14th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int isPrime(int n) {
  5.     if (n==1) return 0;
  6.     int i;
  7.     int j = sqrt(n);
  8.     for (i=2;i<=j;i++) {
  9.         if (n%i == 0) return 0;
  10.     }
  11.     return 1;
  12. }
  13.  
  14. int main() {
  15.     int n;
  16.  
  17.     while (1) {
  18.         scanf("%d",&n);
  19.         if (n==0) {
  20.             break;
  21.         }
  22.         int ara[30000];
  23.         ara[0] = 0;
  24.         int cnt=0;
  25.         int i;
  26.         for (i=1;i<=n/2;i++) {
  27.             if (n%i == 0){
  28.                 ara[cnt] = i;
  29.                 cnt++;
  30.             }
  31.         }
  32.  
  33.         int ans =0;
  34.         int x;
  35.         for (x=0;x<cnt;x++) {
  36.             if (isPrime(ara[x])) {
  37.                 ans++;
  38.             }
  39.         }
  40.  
  41.         printf("%d : %d\n",n,ans);
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment